1、安装 docker-ce
// 安装 docker 依赖
# yum install -y yum-utils device-mapper-persistent-data lvm2
// 配置 docker yum 源为阿里云 yun 源
# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# yum makecache fast
# yum -y install docker-ce
# systemctl start docker
# systemctl enable docker
# docker -v
Docker version 18.03.1-ce, build 9ee9f40
2、配置 docker 镜像源加速器
// 当 Docker Version >= 1.10 时,使用配置文件 /etc/docker/daemon.json(没有时新建该文件)
# cat >> /etc/docker/daemon.json <<EOF
{
"registry-mirrors": ["[https://4wvlvmti.mirror.aliyuncs.com"](https://4wvlvmti.mirror.aliyuncs.com/)]
}
EOF
# systemctl daemon-reload
# systemctl restart docker
// 当 Docker Version < 1.10 时,修改配置文件 /etc/sysconfig/docker 和 /usr/lib/systemd/system/docker.service
# echo "OPTIONS='--registry-mirror=[https://4wvlvmti.mirror.aliyuncs.com'"](https://4wvlvmti.mirror.aliyuncs.com%27/) >> /etc/sysconfig/docker
# sed -i '/ExecStart/i\EnvironmentFile=-/etc/sysconfig/docker/' /usr/lib/systemd/system/docker.service
# sed -i 's#ExecStart=/usr/bin/dockerd#ExecStart=/usr/bin/dockerd $OPTIONS#g' /usr/lib/systemd/system/docker.service
// 修改后的配置文件
# cat /usr/lib/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
EnvironmentFile=-/etc/sysconfig/docker/
ExecStart=/usr/bin/dockerd $OPTIONS
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
# systemctl daemon-reload
# systemctl restart docker
网友评论