花式安装Docker服务

1. yum安装

# 确保yum包更新到最新
yum clean all
yum makecache
yum update -y

安装yum工具:

yum install -y yum-utils device-mapper-persistent-data lvm2

加载docker.repo到默认的/etc/yum.repos.d/下:

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

不指定版本,默认安装最新版本:

yum install -y docker-ce docker-ce-cli containerd.io

指定版本:

# 安装特定版本的docker-ce、docker-ce-cli
# 列出有哪些版本的docker-ce
yum list docker-ce --showduplicates | sort -r

# 列出有哪些版本的docker-ce-cli
yum list docker-ce-cli --showduplicates | sort -r

# 以20.10.24-3.el7版本为例提供参考
yum -y install docker-ce-20.10.24 docker-ce-cli-20.10.24 containerd.io

2. Docker脚本安装

# 运行脚本之前,确保yum包更新到最新
yum update -y

# 第一个是国外镜像, 第二个是国内镜像安装时选择一种方式即可
curl -fsSL https://get.docker.com/ | sh
curl -sSL https://get.daocloud.io/docker | sh

3. RPM包安装

wget下载指定docker版本的rpm包,以18.06.3举例
wget -O /root/docker-ce-18.06.3.ce-3.el7.x86_64.rpm https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-18.06.3.ce-3.el7.x86_64.rpm

# 下载docker的其余依赖包,其中/root/docker-downloader/是指定rpm依赖包下载路径; 后面docker不需要指定版本
yumdownloader --resolve --destdir=/root/downloader-docker/ docker

# 将docker的rpm包和docker依赖的rpm包放在同目录下一起安装
rpm -ivh --nodeps --force ./*.rpm

4. 二进制安装

# 下载源码包,选择tgz包
https://download.docker.com/linux/static/stable/

# 解压安装
wget https://download.docker.com/linux/static/stable/x86_64/docker-18.09.9.tgz
tar -xvf docker-18.09.9.tgz
cp docker/* /usr/bin/

# 生成两个文件到 /etc/systemd/system 下
cd /etc/systemd/system
chmod 755 ./docker.service ./docker.socket
systemctl daemon-reload
systemctl start docker
systemctl enable docker

docker.service

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service containerd.service time-set.target
Wants=network-online.target containerd.service
Requires=docker.socket

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutStartSec=0
RestartSec=2
Restart=always

# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3

# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s

# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity

# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity

# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes

# kill only the docker process, not all processes in the cgroup
KillMode=process
OOMScoreAdjust=-500

[Install]
WantedBy=multi-user.target

docker.socket

[Unit]
Description=Docker Socket for the API

[Socket]
# If /var/run is not implemented as a symlink to /run, you may need to
# specify ListenStream=/var/run/docker.sock instead.
ListenStream=/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker

[Install]
WantedBy=sockets.target

以下是我自己的公众号实用运维,会经常更新我实践过的内容,欢迎大家关注。

  • 8
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值