安装、卸载Docker(CentOS操作系统)

1.centos服务器上安装Docker

官方文档:https://docs.docker.com/engine/install/centos/

1.1操作系统要求

操作系统版本不能低于CentOS 7

1.2卸载旧版本

旧版本的Docker称为dockerdocker-engine
若已安装这些程序,请卸载它们以及相关的依赖项。
若未安装过,则可忽略

#删除旧版本docker
yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
1.3使用存储库进行安装

在一台全新的主机上首次安装Docker Engine之前,需要设置Docker存储库。
设置好之后,可以从存储库安装和更新Docker

1.3.1设置存储库

安装yum-utils软件包(提供yum-config-manager 实用程序)并设置稳定的存储库

#安装yum-utils软件包
yum install -y yum-utils
#设置存储库,官网
yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
[root@VM-0-14-centos /]# yum-config-manager \
>     --add-repo \
>     https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror, langpacks
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
[root@VM-0-14-centos /]# 

1.4安装Docker引擎
1.4.1安装最新版本的Docker Engine和容器
yum install docker-ce docker-ce-cli containerd.io

示例

[root@VM-0-14-centos /]# yum install docker-ce docker-ce-cli containerd.io
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package containerd.io.x86_64 0:1.4.3-3.1.el7 will be installed
....
Install  3 Packages (+12 Dependent packages)

Total download size: 104 M
Installed size: 428 M
Is this ok [y/d/N]: y  #输入y 安装软件包
....
Total                                                                                                                              8.2 MB/s | 104 MB  00:00:12     
Retrieving key from https://download.docker.com/linux/centos/gpg
Importing GPG key 0x621E9F35:
 Userid     : "Docker Release (CE rpm) <docker@docker.com>"
 Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
 From       : https://download.docker.com/linux/centos/gpg
 #验证指纹是否匹配【060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35】
Is this ok [y/N]:   ###若匹配,则输入 y 
Installed:
  containerd.io.x86_64 0:1.4.3-3.1.el7                   docker-ce.x86_64 3:20.10.3-3.el7                   docker-ce-cli.x86_64 1:20.10.3-3.el7                  

Dependency Installed:
  audit-libs-python.x86_64 0:2.8.5-4.el7                  checkpolicy.x86_64 0:2.5-8.el7                container-selinux.noarch 2:2.119.2-1.911c772.el7_8       
  docker-ce-rootless-extras.x86_64 0:20.10.3-3.el7        fuse-overlayfs.x86_64 0:0.7.2-6.el7_8         fuse3-libs.x86_64 0:3.6.1-4.el7                          
  libcgroup.x86_64 0:0.41-21.el7                          libsemanage-python.x86_64 0:2.5-14.el7        policycoreutils-python.x86_64 0:2.5-34.el7               
  python-IPy.noarch 0:0.75-6.el7                          setools-libs.x86_64 0:3.3.8-4.el7             slirp4netns.x86_64 0:0.4.3-4.el7_8                       

Complete! #安装成功
1.4.2安装指定版本

列出并排序存储库中可用的版本。按版本号(从高到低)对结果进行排序,并被截断

yum list docker-ce --showduplicates | sort -r

示例

[root@VM-0-14-centos /]# yum list docker-ce --showduplicates | sort -r
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror, langpacks
docker-ce.x86_64            3:20.10.3-3.el7                     docker-ce-stable
docker-ce.x86_64            3:20.10.2-3.el7                     docker-ce-stable
....#省略
Available Packages
[root@VM-0-14-centos /]# 

<VERSION_STRING>:版本字符串
上述第2列,从第一个冒号(:)开始,连字符(-)分隔。例,docker-ce-20.10.3

yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io

示例

[root@VM-0-14-centos /]# yum install docker-ce-20.10.3 docker-ce-cli-20.10.3 containerd.io
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
....
---> Package docker-ce-rootless-extras.x86_64 0:20.10.3-3.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================================================================
 Package                                         Arch                         Version                                 Repository                              Size
===================================================================================================================================================================
Installing:
 containerd.io                                   x86_64                       1.4.3-3.1.el7                           docker-ce-stable                        33 M
 docker-ce                                       x86_64                       3:20.10.3-3.el7                         docker-ce-stable                        27 M
 docker-ce-cli                                   x86_64                       1:20.10.3-3.el7                         docker-ce-stable                        33 M
Installing for dependencies:
 docker-ce-rootless-extras                       x86_64                       20.10.3-3.el7                           docker-ce-stable                       9.0 M

Transaction Summary
===================================================================================================================================================================
Install  3 Packages (+1 Dependent package)

Total download size: 102 M
Installed size: 422 M
Is this ok [y/d/N]: y
Downloading packages:
(1/4): docker-ce-20.10.3-3.el7.x86_64.rpm                                                                                                   |  27 MB  00:00:07     
(2/4): containerd.io-1.4.3-3.1.el7.x86_64.rpm                                                                                               |  33 MB  00:00:13     
(3/4): docker-ce-rootless-extras-20.10.3-3.el7.x86_64.rpm                                                                                   | 9.0 MB  00:00:04     
(4/4): docker-ce-cli-20.10.3-3.el7.x86_64.rpm                                                                                               |  33 MB  00:00:12     
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                              5.0 MB/s | 102 MB  00:00:20     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 1:docker-ce-cli-20.10.3-3.el7.x86_64                                                                                                            1/4 
  Installing : containerd.io-1.4.3-3.1.el7.x86_64                                                                                                              2/4 
  Installing : 3:docker-ce-20.10.3-3.el7.x86_64                                                                                                                3/4 
  Installing : docker-ce-rootless-extras-20.10.3-3.el7.x86_64                                                                                                  4/4 
  Verifying  : docker-ce-rootless-extras-20.10.3-3.el7.x86_64                                                                                                  1/4 
  Verifying  : containerd.io-1.4.3-3.1.el7.x86_64                                                                                                              2/4 
  Verifying  : 3:docker-ce-20.10.3-3.el7.x86_64                                                                                                                3/4 
  Verifying  : 1:docker-ce-cli-20.10.3-3.el7.x86_64                                                                                                            4/4 

Installed:
  containerd.io.x86_64 0:1.4.3-3.1.el7                   docker-ce.x86_64 3:20.10.3-3.el7                   docker-ce-cli.x86_64 1:20.10.3-3.el7                  

Dependency Installed:
  docker-ce-rootless-extras.x86_64 0:20.10.3-3.el7                                                                                                                 

Complete!
1.4.3启动docker
#启动docker
systemctl start docker
#查看docker进程是否启动
ps -ef|grep docker

示例

[root@VM-0-14-centos /]# systemctl start docker 
[root@VM-0-14-centos /]# ps -ef|grep docker
root     21135     1  0 11:29 ?        00:00:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
root     21314  9399  0 11:29 pts/0    00:00:00 grep --color=auto docker
[root@VM-0-14-centos /]# 
1.4.4通过运行hello-world 镜像来验证是否正确安装Docker Engine
docker run hello-world

示例

[root@VM-0-14-centos /]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete 
Digest: sha256:31b9c7d48790f0d8c50ab433d9c3b7e17666d6993084c002c2ff1ca09b96391d
Status: Downloaded newer image for hello-world:latest

Hello from Docker! 
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/
 
[root@VM-0-14-centos /]# 

2.卸载Docker

2.1卸载Docker Engine,CLIContainerd软件包
yum remove docker-ce docker-ce-cli containerd.io

示例

[root@VM-0-14-centos /]# yum remove docker-ce docker-ce-cli containerd.io
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
--> Running transaction check
---> Package containerd.io.x86_64 0:1.4.3-3.1.el7 will be erased
---> Package docker-ce.x86_64 3:20.10.3-3.el7 will be erased
--> Processing Dependency: docker-ce for package: docker-ce-rootless-extras-20.10.3-3.el7.x86_64
---> Package docker-ce-cli.x86_64 1:20.10.3-3.el7 will be erased
--> Running transaction check
---> Package docker-ce-rootless-extras.x86_64 0:20.10.3-3.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================================================================
 Package                                         Arch                         Version                                Repository                               Size
===================================================================================================================================================================
Removing:
 containerd.io                                   x86_64                       1.4.3-3.1.el7                          @docker-ce-stable                       127 M
 docker-ce                                       x86_64                       3:20.10.3-3.el7                        @docker-ce-stable                       115 M
 docker-ce-cli                                   x86_64                       1:20.10.3-3.el7                        @docker-ce-stable                       156 M
Removing for dependencies:
 docker-ce-rootless-extras                       x86_64                       20.10.3-3.el7                          @docker-ce-stable                        24 M

Transaction Summary
===================================================================================================================================================================
Remove  3 Packages (+1 Dependent package)

Installed size: 422 M
Is this ok [y/N]: y  ##输入y确认删除
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : 3:docker-ce-20.10.3-3.el7.x86_64                                                                                                                1/4 
  Erasing    : docker-ce-rootless-extras-20.10.3-3.el7.x86_64                                                                                                  2/4 
  Erasing    : containerd.io-1.4.3-3.1.el7.x86_64                                                                                                              3/4 
  Erasing    : 1:docker-ce-cli-20.10.3-3.el7.x86_64                                                                                                            4/4 
  Verifying  : docker-ce-rootless-extras-20.10.3-3.el7.x86_64                                                                                                  1/4 
  Verifying  : containerd.io-1.4.3-3.1.el7.x86_64                                                                                                              2/4 
  Verifying  : 3:docker-ce-20.10.3-3.el7.x86_64                                                                                                                3/4 
  Verifying  : 1:docker-ce-cli-20.10.3-3.el7.x86_64                                                                                                            4/4 

Removed:
  containerd.io.x86_64 0:1.4.3-3.1.el7                   docker-ce.x86_64 3:20.10.3-3.el7                   docker-ce-cli.x86_64 1:20.10.3-3.el7                  

Dependency Removed:
  docker-ce-rootless-extras.x86_64 0:20.10.3-3.el7                                                                                                                 

Complete!
[root@VM-0-14-centos /]# 
2.2必须手动删除所有已编辑的配置文件

主机上的镜像,容器,卷或自定义配置文件不会自动删除。要删除所有图像,容器和卷

rm -rf /var/lib/docker

示例

[root@VM-0-14-centos /]# rm -rf /var/lib/docker
[root@VM-0-14-centos /]# 

Docker常用命令(一)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

shexianyu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值