安装完docker后,查看服务状态正常:

[root@kn06 guacamole]# systemctl status docker 
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2024-08-01 18:47:09 CST; 2h 59min ago
     Docs: https://docs.docker.com
 Main PID: 17831 (dockerd)
    Tasks: 52
   Memory: 68.9M
   CGroup: /system.slice/docker.service
           ├─17831 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
           ├─18840 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 33070 -container-ip 172.17.0.2 -container-port 33060
           ├─18846 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 33070 -container-ip 172.17.0.2 -container-port 33060
           ├─18858 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 3307 -container-ip 172.17.0.2 -container-port 3306
           ├─18864 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 3307 -container-ip 172.17.0.2 -container-port 3306
           ├─19563 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 9090 -container-ip 172.17.0.4 -container-port 8080
           └─19568 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 9090 -container-ip 172.17.0.4 -container-port 8080

Aug 01 18:47:09 kn06 dockerd[17831]: time="2024-08-01T18:47:09.377147299+08:00" level=info msg="Docker daemon" commit=de5c9cf containerd-snapshotter=false st...sion=26.1.4
Aug 01 18:47:09 kn06 dockerd[17831]: time="2024-08-01T18:47:09.377290705+08:00" level=info msg="Daemon has completed initialization"
Aug 01 18:47:09 kn06 dockerd[17831]: time="2024-08-01T18:47:09.403833686+08:00" level=info msg="API listen on /run/docker.sock"
Aug 01 18:47:09 kn06 systemd[1]: Started Docker Application Container Engine.
Aug 01 18:47:13 kn06 dockerd[17831]: time="2024-08-01T18:47:13.364102186+08:00" level=error msg="Handler for POST /v1.45/containers/1b40b6d572bd/restart returned error:...
Aug 01 18:49:04 kn06 dockerd[17831]: time="2024-08-01T18:49:04.504796281+08:00" level=info msg="ignoring event" container=7e170c0bc34e4e05620204218661759f16d...TaskDelete"
Aug 01 18:49:34 kn06 dockerd[17831]: time="2024-08-01T18:49:34.091780400+08:00" level=info msg="ignoring event" container=d677c6971061b5e00284f8ead181671c08e...TaskDelete"
Aug 01 18:50:24 kn06 dockerd[17831]: time="2024-08-01T18:50:24.811984096+08:00" level=info msg="ignoring event" container=c068a9b6b930826793ba1cb1e5a81f536f6...TaskDelete"
Aug 01 18:54:14 kn06 dockerd[17831]: time="2024-08-01T18:54:14.857073437+08:00" level=info msg="ignoring event" container=61a7db3e0f878cb2e83c59dc55b248236f3...TaskDelete"
Aug 01 18:54:24 kn06 dockerd[17831]: time="2024-08-01T18:54:24.306856022+08:00" level=info msg="ignoring event" container=564ad086bdb9c7fc20b4adbf7233cc2a975...TaskDelete"
Hint: Some lines were ellipsized, use -l to show in full.
[root@kn06 guacamole]# 

但是执行docker命令提示command not found

[root@kn06 guacamole]# docker --version
command not found

卸载已安装的docker

先暂停docker服务

[root@kn06 ~]# systemctl stop docker
卸载Docker软件包:

[root@kn06 ~]# sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine

以上卸载时,如果提示:

Loaded plugins: fastestmirror
No Match for argument: docker
No Match for argument: docker-client
No Match for argument: docker-client-latest
No Match for argument: docker-common
No Match for argument: docker-latest
No Match for argument: docker-latest-logrotate
No Match for argument: docker-logrotate
No Match for argument: docker-engine
No Packages marked for removal

说明并没有找到这些包并删除,那么我们会发现,docker已经存在,没有卸载成功

这时候我们可以尝试使用以下命令查找已安装的docker相关包:

yum list installed | grep docker
[root@kn06 ~]# yum list installed | grep docker
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
containerd.io.x86_64                    1.6.33-3.1.el7                 @docker-ce-stable
docker-buildx-plugin.x86_64             0.14.1-1.el7                   @docker-ce-stable
docker-ce.x86_64                        3:26.1.4-1.el7                 @docker-ce-stable
docker-ce-cli.x86_64                    1:26.1.4-1.el7                 @docker-ce-stable
docker-ce-rootless-extras.x86_64        26.1.4-1.el7                   @docker-ce-stable
docker-compose-plugin.x86_64            2.27.1-1.el7                   @docker-ce-stable

这个命令将列出所有已安装的包,并通过 grep 过滤出包含 "docker" 的包。如果这个命令返回了结果,那么你可以使用返回的包名来卸载 Docker

而以上则是返回了相关的docker包,我们将这些包进行卸载:

sudo yum remove containerd.io.x86_64 docker-buildx-plugin.x86_64 docker-ce.x86_64 docker-ce-cli.x86_64 docker-ce-rootless-extras.x86_64 docker-compose-plugin.x86_64

tip:以上命令,除了前面的"sudo yum remove"是固定的,后面的包则需要根据实际的情况拼接,以上只是博主的内容,切勿直接复制使用,可能会发生错误或卸载不完整!

在卸载过程中,会提示:

Is this ok [y/N]: 

我们输入"y"按下回车键 代表同意即可

卸载运行之后会出现:

Complete!

就代表卸载完成了

安装:

更新本地镜像源:更新本地镜像源:

# 设置docker镜像源
yum-config-manager \
    --add-repo \
    https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    
sed -i 's/download.docker.com/mirrors.aliyun.com\/docker-ce/g' /etc/yum.repos.d/docker-ce.repo

yum makecache fast

安装

yum install -y docker-ce

docker-ce为社区免费版本。稍等片刻,docker即可安装成功。

[root@kn06 ~]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2024-08-01 18:47:09 CST; 3h 6min ago
     Docs: https://docs.docker.com
 Main PID: 17831 (dockerd)
    Tasks: 52
   Memory: 62.6M
   CGroup: /system.slice/docker.service
           ├─17831 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
           ├─18840 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 33070 -container-ip 172.17.0.2 -container-port 33060
           ├─18846 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 33070 -container-ip 172.17.0.2 -container-port 33060
           ├─18858 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 3307 -container-ip 172.17.0.2 -container-port 3306
           ├─18864 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 3307 -container-ip 172.17.0.2 -container-port 3306
           ├─19563 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 9090 -container-ip 172.17.0.4 -container-port 8080
           └─19568 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 9090 -container-ip 172.17.0.4 -container-port 8080

Aug 01 18:47:09 kn06 dockerd[17831]: time="2024-08-01T18:47:09.377147299+08:00" level=info msg="Docker daemon" commit=de5c9cf containerd-snapshotter=false st...sion=26.1.4
Aug 01 18:47:09 kn06 dockerd[17831]: time="2024-08-01T18:47:09.377290705+08:00" level=info msg="Daemon has completed initialization"
Aug 01 18:47:09 kn06 dockerd[17831]: time="2024-08-01T18:47:09.403833686+08:00" level=info msg="API listen on /run/docker.sock"
Aug 01 18:47:09 kn06 systemd[1]: Started Docker Application Container Engine.
Aug 01 18:47:13 kn06 dockerd[17831]: time="2024-08-01T18:47:13.364102186+08:00" level=error msg="Handler for POST /v1.45/containers/1b40b6d572bd/restart returned error:...
Aug 01 18:49:04 kn06 dockerd[17831]: time="2024-08-01T18:49:04.504796281+08:00" level=info msg="ignoring event" container=7e170c0bc34e4e05620204218661759f16d...TaskDelete"
Aug 01 18:49:34 kn06 dockerd[17831]: time="2024-08-01T18:49:34.091780400+08:00" level=info msg="ignoring event" container=d677c6971061b5e00284f8ead181671c08e...TaskDelete"
Aug 01 18:50:24 kn06 dockerd[17831]: time="2024-08-01T18:50:24.811984096+08:00" level=info msg="ignoring event" container=c068a9b6b930826793ba1cb1e5a81f536f6...TaskDelete"
Aug 01 18:54:14 kn06 dockerd[17831]: time="2024-08-01T18:54:14.857073437+08:00" level=info msg="ignoring event" container=61a7db3e0f878cb2e83c59dc55b248236f3...TaskDelete"
Aug 01 18:54:24 kn06 dockerd[17831]: time="2024-08-01T18:54:24.306856022+08:00" level=info msg="ignoring event" container=564ad086bdb9c7fc20b4adbf7233cc2a975...TaskDelete"
Hint: Some lines were ellipsized, use -l to show in full.
[root@kn06 ~]# 
08-07 04:49