一、简介
二、准备
Docker 要求 CentOS 系统的内核版本高于 3.10
uname -r
使用
root
登录 Centos。确保 yum 包更新到最新。
sudo yum update
卸载旧版本
sudo yum remove docker docker-common docker-selinux docker-engine
安装依赖
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
三、安装
外网安装
- 设置yum源
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
- 查看所有仓库中所有docker版本
yum list docker-ce --showduplicates | sort -r
- 安装
sudo yum install docker-19.03.4
- 设置开机自启
$ sudo systemctl enable docker
- 启动docker
$ sudo systemctl start docker
内网安装
- 解压
tar -zxvf docker-19.03.4.tgz
- 将解压出来的docker文件内容移动到/usr/bin/目录下
cp docker/* /usr/bin/
- 将docker注册为service
vim /etc/systemd/system/docker.service
内容
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[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
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# 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
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
- 添加文件权限
chmod +x /etc/systemd/system/docker.service
docker默认网关IP为172.17网段,如果本地网络为172.17,则需要修改docker默认网关IP,防止与本地网络产生冲突
cat << EOF > /etc/docker/daemon.json
{
"bip": "172.27.0.1/16"
}
EOF
- 重载unit配置文件
systemctl daemon-reload
- 设置开机自启
systemctl enable docker.service
- 启动docker
systemctl start docker
四、验证
- 查看Docker状态
systemctl status docker
- 查看Docker版本
docker -v