删除旧版docker
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
安装必须的依赖
yum install -y gcc gcc-c++ yum-utils
配置阿里云docker的yum源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache
安装docker
yum install -y docker-ce docker-ce-cli containerd.io
启动docker和设置开机启动
systemctl start docker
systemctl enable docker
设置阿里云docker镜像仓库地址
mkdir -p /etc/docker
#此处可以替换自己的仓库地址,在阿里云容器镜像服务中,用自己的账号生成一个就行
tee /etc/docker/daemon.json <<-'EOF'
{
"exec-opts":["native.cgroupdriver=systemd"],
"registry-mirrors": ["https://g4m1nbps.mirror.aliyuncs.com"]
}
EOF
安装docker-compose
下载地址:github仓库地址
wget -O https://github.91chi.fun//https://github.com//docker/compose/releases/download/v2.2.3/docker-compose-linux-x86_64 /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
配置docker自动部署端口
/lib/systemd/system/docker.service文件,在ExecStart的值后面添加-H tcp://0.0.0.0:32375 -H unix:///var/run/docker.sock
可以自定义修改端口32375
以下是完整的修改后docker.service文件内容,可直接复制替换
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket containerd.service
[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 -H tcp://0.0.0.0:32375 -H unix:///var/run/docker.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=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.
LimitNOFILE=infinity
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
systemctl daemon-reload
systemctl restart docker
可以通过http://ip:32375/version 查看是否配置成功
可选:配置docker自动部署域名
配置nginx反向代理域名到http://ip:32375