一、卸载
- 查看当前版本
docker -v
2. 如果有,先停止docker
systemctl stop docker
- 如果是yum安装,卸载方式为
#已防版本冲突,直接卸载
yum remove docker \docker-client \docker-client-latest \docker-common \docker-latest \docker-latest-logrotate \docker-logrotate \docker-engine
如果为二进制离线安装,则卸载方式为
删除docker配置文件目录
rm -rf /etc/docker
删除docker service文件目录
rm -rf /etc/systemd/system/docker.service
或
rm -rf /usr/lib/systemd/system/docker.service
删除docker部署目录
# 如果配置文件中指定了docker-root配置项,则删除该配置项对应的目录
rm -rf /home/docker_data
# 如果配置项中未指定docker-root配置项,则docker会被部署到/var/lib/docker目录下
rm -rf /var/lib/docker
卸载docker存储库
rm -rf /etc/yum.repos.d/docker-ce.repo
重启服务
reboot
二、安装
二进制安装
-
阿里云下载安装包:https://mirrors.aliyun.com/docker-ce/linux/static/stable/x86_64/
-
解压,移动
tar -zvxf docker-26.0.0.tgz
cp docker/* /usr/bin/
- 注册服务,新建 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
- 将 docker.service 拷贝到
cp docker.service /usr/lib/systemd/system/
- 重新加载配置文件
systemctl daemon-reload
- 启动docker
systemctl start docker
- 查看docker状态
systemctl status docker
- 设置开机自启
systemctl enable docker
注意:如果启动docker提示"Failed to execute operation: Bad message",可能复制docker.service文件时,[Unit] 变成了 t],又或者ExecStart 写成Execstart。
配置镜像参考:https://blog.csdn.net/u014390502/article/details/143472743
比如:https://docker.tbedu.top/