1. 程式人生 > 其它 >Linux CentOS7 系統下安裝及解除安裝Docker

Linux CentOS7 系統下安裝及解除安裝Docker

十年河東,十年河西,莫欺少年窮

學無止境,精益求精

官方文件:https://docs.docker.com/ 

1、檢視Linux作業系統

切換目錄到etc

sudo cd /etc/

檢視系統配置

cat os-release

我的配置如下:

NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

由上可知,我的系統為CentOS 7

3、安裝之前寫清除之前安裝的Docker

sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

 4、安裝yum-utils包(提供yum-config-manager 實用程式)

sudo yum install -y yum-utils

5、配置映象地址【官方文件提供的映象地址為國外伺服器地址,非常慢,這裡使用阿里雲映象地址】

sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

6、重新建立快取區【使配置的映象地址生效】

yum makecache fast

7、安裝docker 【安裝過程中會有提問,輸入 y 繼續下一步】

sudo yum install docker-ce docker-ce-cli containerd.io

8、開啟docker 【類似於windows服務】

start docker

9、檢查docker 是否安裝成功

docker -v

如果輸出以下內容,則證明安裝成功

Docker version 20.10.14, build a224086

 

解除安裝 Docker 引擎

  1. 解除安裝 Docker 引擎、CLI 和 Containerd 軟體包:

sudo yum remove docker-ce docker-ce-cli containerd.io

2.移除安裝檔案及相關容器

 sudo rm -rf /var/lib/docker
 sudo rm -rf /var/lib/containerd

參考文件:https://docs.docker.com/engine/install/centos/

我的全部指令碼

[root@localhost etc]# cat os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

[root@localhost etc]# clear

[root@localhost etc]# sudo yum remove docker \
>                   docker-client \
>                   docker-client-latest \
>                   docker-common \
>                   docker-latest \
>                   docker-latest-logrotate \
>                   docker-logrotate \
>                   docker-engine
已載入外掛:fastestmirror, langpacks
引數 docker 沒有匹配
引數 docker-client 沒有匹配
引數 docker-client-latest 沒有匹配
引數 docker-common 沒有匹配
引數 docker-latest 沒有匹配
引數 docker-latest-logrotate 沒有匹配
引數 docker-logrotate 沒有匹配
引數 docker-engine 沒有匹配
不刪除任何軟體包
[root@localhost etc]# sudo yum install -y yum-utils
已載入外掛:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.cn99.com
 * extras: mirrors.cn99.com
 * updates: mirrors.cn99.com
base                                          | 3.6 kB     00:00     
extras                                        | 2.9 kB     00:00     
updates                                       | 2.9 kB     00:00     
(1/4): base/7/x86_64/group_gz                   | 153 kB   00:00     
(2/4): extras/7/x86_64/primary_db               | 246 kB   00:00     
(3/4): base/7/x86_64/primary_db                 | 6.1 MB   00:03     
(4/4): updates/7/x86_64/primary_db              |  14 MB   00:07     
軟體包 yum-utils-1.1.31-54.el7_8.noarch 已安裝並且是最新版本
無須任何處理
[root@localhost etc]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
已載入外掛:fastestmirror, langpacks
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
[root@localhost etc]# yum makecache fast
已載入外掛:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.ustc.edu.cn
 * extras: mirrors.ustc.edu.cn
 * updates: mirrors.ustc.edu.cn
base                                          | 3.6 kB     00:00     
docker-ce-stable                              | 3.5 kB     00:00     
extras                                        | 2.9 kB     00:00     
updates                                       | 2.9 kB     00:00     
(1/2): docker-ce-stable/7/x86_64/updateinfo     |   55 B   00:00     
(2/2): docker-ce-stable/7/x86_64/primary_db     |  75 kB   00:00     
元資料快取已建立
[root@localhost etc]# sudo yum install docker-ce docker-ce-cli containerd.io
已載入外掛:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.ustc.edu.cn
 * extras: mirrors.ustc.edu.cn
 * updates: mirrors.ustc.edu.cn
正在解決依賴關係
--> 正在檢查事務
---> 軟體包 containerd.io.x86_64.0.1.5.11-3.1.el7 將被 安裝
--> 正在處理依賴關係 container-selinux >= 2:2.74,它被軟體包 containerd.io-1.5.11-3.1.el7.x86_64 需要
---> 軟體包 docker-ce.x86_64.3.20.10.14-3.el7 將被 安裝
--> 正在處理依賴關係 docker-ce-rootless-extras,它被軟體包 3:docker-ce-20.10.14-3.el7.x86_64 需要
---> 軟體包 docker-ce-cli.x86_64.1.20.10.14-3.el7 將被 安裝
--> 正在處理依賴關係 docker-scan-plugin(x86-64),它被軟體包 1:docker-ce-cli-20.10.14-3.el7.x86_64 需要
--> 正在檢查事務
---> 軟體包 container-selinux.noarch.2.2.119.2-1.911c772.el7_8 將被 安裝
---> 軟體包 docker-ce-rootless-extras.x86_64.0.20.10.14-3.el7 將被 安裝
--> 正在處理依賴關係 fuse-overlayfs >= 0.7,它被軟體包 docker-ce-rootless-extras-20.10.14-3.el7.x86_64 需要
--> 正在處理依賴關係 slirp4netns >= 0.4,它被軟體包 docker-ce-rootless-extras-20.10.14-3.el7.x86_64 需要
---> 軟體包 docker-scan-plugin.x86_64.0.0.17.0-3.el7 將被 安裝
--> 正在檢查事務
---> 軟體包 fuse-overlayfs.x86_64.0.0.7.2-6.el7_8 將被 安裝
--> 正在處理依賴關係 libfuse3.so.3(FUSE_3.2)(64bit),它被軟體包 fuse-overlayfs-0.7.2-6.el7_8.x86_64 需要
--> 正在處理依賴關係 libfuse3.so.3(FUSE_3.0)(64bit),它被軟體包 fuse-overlayfs-0.7.2-6.el7_8.x86_64 需要
--> 正在處理依賴關係 libfuse3.so.3()(64bit),它被軟體包 fuse-overlayfs-0.7.2-6.el7_8.x86_64 需要
---> 軟體包 slirp4netns.x86_64.0.0.4.3-4.el7_8 將被 安裝
--> 正在檢查事務
---> 軟體包 fuse3-libs.x86_64.0.3.6.1-4.el7 將被 安裝
--> 解決依賴關係完成

依賴關係解決

=====================================================================
 Package             架構   版本              源                大小
=====================================================================
正在安裝:
 containerd.io       x86_64 1.5.11-3.1.el7    docker-ce-stable  29 M
 docker-ce           x86_64 3:20.10.14-3.el7  docker-ce-stable  22 M
 docker-ce-cli       x86_64 1:20.10.14-3.el7  docker-ce-stable  30 M
為依賴而安裝:
 container-selinux   noarch 2:2.119.2-1.911c772.el7_8
                                              extras            40 k
 docker-ce-rootless-extras
                     x86_64 20.10.14-3.el7    docker-ce-stable 8.1 M
 docker-scan-plugin  x86_64 0.17.0-3.el7      docker-ce-stable 3.7 M
 fuse-overlayfs      x86_64 0.7.2-6.el7_8     extras            54 k
 fuse3-libs          x86_64 3.6.1-4.el7       extras            82 k
 slirp4netns         x86_64 0.4.3-4.el7_8     extras            81 k

事務概要
=====================================================================
安裝  3 軟體包 (+6 依賴軟體包)

總下載量:94 M
安裝大小:378 M
Is this ok [y/d/N]: y
Downloading packages:
警告:/var/cache/yum/x86_64/7/extras/packages/container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm: 頭V3 RSA/SHA256 Signature, 金鑰 ID f4a80eb5: NOKEY
container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm 的公鑰尚未安裝
(1/9): container-selinux-2.119.2-1.911c772.el7_ |  40 kB   00:00     
警告:/var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-20.10.14-3.el7.x86_64.rpm: 頭V4 RSA/SHA512 Signature, 金鑰 ID 621e9f35: NOKEY
docker-ce-20.10.14-3.el7.x86_64.rpm 的公鑰尚未安裝
(2/9): docker-ce-20.10.14-3.el7.x86_64.rpm      |  22 MB   00:20     
(3/9): containerd.io-1.5.11-3.1.el7.x86_64.rpm  |  29 MB   00:22     
(4/9): docker-ce-rootless-extras-20.10.14-3.el7 | 8.1 MB   00:08     
(5/9): fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm  |  54 kB   00:00     
(6/9): slirp4netns-0.4.3-4.el7_8.x86_64.rpm     |  81 kB   00:00     
(7/9): fuse3-libs-3.6.1-4.el7.x86_64.rpm        |  82 kB   00:00     
(8/9): docker-scan-plugin-0.17.0-3.el7.x86_64.r | 3.7 MB   00:03     
(9/9): docker-ce-cli-20.10.14-3.el7.x86_64.rpm  |  30 MB   00:22     
---------------------------------------------------------------------
總計                                    2.2 MB/s |  94 MB  00:42     
從 https://mirrors.aliyun.com/docker-ce/linux/centos/gpg 檢索金鑰
匯入 GPG key 0x621E9F35:
 使用者ID     : "Docker Release (CE rpm) <[email protected]>"
 指紋       : 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
 來自       : https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
是否繼續?[y/N]:y
從 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 檢索金鑰
匯入 GPG key 0xF4A80EB5:
 使用者ID     : "CentOS-7 Key (CentOS 7 Official Signing Key) <[email protected]>"
 指紋       : 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 軟體包     : centos-release-7-9.2009.0.el7.centos.x86_64 (@anaconda)
 來自       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
是否繼續?[y/N]:y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安裝    : docker-scan-plugin-0.17.0-3.el7.x86_64           1/9 
  正在安裝    : 1:docker-ce-cli-20.10.14-3.el7.x86_64            2/9 
  正在安裝    : 2:container-selinux-2.119.2-1.911c772.el7_8.no   3/9 
  正在安裝    : containerd.io-1.5.11-3.1.el7.x86_64              4/9 
  正在安裝    : slirp4netns-0.4.3-4.el7_8.x86_64                 5/9 
  正在安裝    : fuse3-libs-3.6.1-4.el7.x86_64                    6/9 
  正在安裝    : fuse-overlayfs-0.7.2-6.el7_8.x86_64              7/9 
  正在安裝    : docker-ce-rootless-extras-20.10.14-3.el7.x86_6   8/9 
  正在安裝    : 3:docker-ce-20.10.14-3.el7.x86_64                9/9 
  驗證中      : 3:docker-ce-20.10.14-3.el7.x86_64                1/9 
  驗證中      : containerd.io-1.5.11-3.1.el7.x86_64              2/9 
  驗證中      : fuse3-libs-3.6.1-4.el7.x86_64                    3/9 
  驗證中      : fuse-overlayfs-0.7.2-6.el7_8.x86_64              4/9 
  驗證中      : docker-ce-rootless-extras-20.10.14-3.el7.x86_6   5/9 
  驗證中      : slirp4netns-0.4.3-4.el7_8.x86_64                 6/9 
  驗證中      : 2:container-selinux-2.119.2-1.911c772.el7_8.no   7/9 
  驗證中      : 1:docker-ce-cli-20.10.14-3.el7.x86_64            8/9 
  驗證中      : docker-scan-plugin-0.17.0-3.el7.x86_64           9/9 

已安裝:
  containerd.io.x86_64 0:1.5.11-3.1.el7                              
  docker-ce.x86_64 3:20.10.14-3.el7                                  
  docker-ce-cli.x86_64 1:20.10.14-3.el7                              

作為依賴被安裝:
  container-selinux.noarch 2:2.119.2-1.911c772.el7_8                 
  docker-ce-rootless-extras.x86_64 0:20.10.14-3.el7                  
  docker-scan-plugin.x86_64 0:0.17.0-3.el7                           
  fuse-overlayfs.x86_64 0:0.7.2-6.el7_8                              
  fuse3-libs.x86_64 0:3.6.1-4.el7                                    
  slirp4netns.x86_64 0:0.4.3-4.el7_8                                 

完畢!
[root@localhost etc]# start docker
bash: start: 未找到命令...
[root@localhost etc]# sudo systemctl start docker
[root@localhost etc]# sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:bfea6278a0a267fad2634554f4f0c6f31981eea41c553fdf5a83e95a41d40c38
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@localhost etc]# docker -v
Docker version 20.10.14, build a224086
[root@localhost etc]# 
View Code

@天才臥龍的部落格