一、簡介
二、準備
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