centos 線上安裝 docker

哈哈哈hh發表於2021-12-14

映象下載、域名解析、時間同步請點選  阿里巴巴開源映象站

在新主機上首次安裝Docker Engine之前,需要設定Docker儲存庫。之後,您可以從儲存庫安裝和更新Docker。
設定儲存庫
安裝yum-utils軟體包(提供yum-config-manager 實用程式)並設定穩定的儲存庫。
[root@localhost ~]# yum install -y yum-utils已載入外掛:fastestmirror, langpacksLoading mirror speeds from cached hostfile
 * base: mirror.lzu.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com正在解決依賴關係--> 正在檢查事務---> 軟體包 yum-utils.noarch.0.1.1.31-24.el7 將被 升級---> 軟體包 yum-utils.noarch.0.1.1.31-52.el7 將被 更新--> 正在處理依賴關係 yum >= 3.4.3-143,它被軟體包 yum-utils-1.1.31-52.el7.noarch 需要--> 正在檢查事務---> 軟體包 yum.noarch.0.3.4.3-118.el7.centos 將被 升級---> 軟體包 yum.noarch.0.3.4.3-163.el7.centos 將被 更新--> 正在處理依賴關係 rpm >= 4.11.3-22,它被軟體包 yum-3.4.3-163.el7.centos.noarch 需要--> 正在處理依賴關係 python-urlgrabber >= 3.10-8,它被軟體包 yum-3.4.3-163.el7.centos.noarch 需要--> 正在檢查事務---> 軟體包 python-urlgrabber.noarch.0.3.10-4.el7 將被 升級---> 軟體包 python-urlgrabber.noarch.0.3.10-9.el7 將被 更新---> 軟體包 rpm.x86_64.0.4.11.1-16.el7 將被 升級--> 正在處理依賴關係 rpm = 4.11.1-16.el7,它被軟體包 rpm-python-4.11.1-16.el7.x86_64 需要--> 正在處理依賴關係 rpm = 4.11.1-16.el7,它被軟體包 rpm-libs-4.11.1-16.el7.x86_64 需要---> 軟體包 rpm.x86_64.0.4.11.3-40.el7 將被 更新--> 正在檢查事務---> 軟體包 rpm-libs.x86_64.0.4.11.1-16.el7 將被 升級--> 正在處理依賴關係 rpm-libs(x86-64) = 4.11.1-16.el7,它被軟體包 rpm-build-libs-4.11.1-16.el7.x86_64 需要---> 軟體包 rpm-libs.x86_64.0.4.11.3-40.el7 將被 更新---> 軟體包 rpm-python.x86_64.0.4.11.1-16.el7 將被 升級---> 軟體包 rpm-python.x86_64.0.4.11.3-40.el7 將被 更新--> 正在檢查事務---> 軟體包 rpm-build-libs.x86_64.0.4.11.1-16.el7 將被 升級---> 軟體包 rpm-build-libs.x86_64.0.4.11.3-40.el7 將被 更新--> 解決依賴關係完成依賴關係解決============================================================================================================================================================================================================================
 Package                                                   架構                                           版本                                                           源                                            大小============================================================================================================================================================================================================================正在更新:
 yum-utils                                                 noarch                                         1.1.31-52.el7                                                  base                                         121 k為依賴而更新:
 python-urlgrabber                                         noarch                                         3.10-9.el7                                                     base                                         108 k
 rpm                                                       x86_64                                         4.11.3-40.el7                                                  base                                         1.2 M
 rpm-build-libs                                            x86_64                                         4.11.3-40.el7                                                  base                                         107 k
 rpm-libs                                                  x86_64                                         4.11.3-40.el7                                                  base                                         278 k
 rpm-python                                                x86_64                                         4.11.3-40.el7                                                  base                                          83 k
 yum                                                       noarch                                         3.4.3-163.el7.centos                                           base                                         1.2 M事務概要============================================================================================================================================================================================================================升級  1 軟體包 (+6 依賴軟體包)總計:3.1 MDownloading packages:Running transaction checkRunning transaction testTransaction test succeededRunning transaction
  正在更新    : rpm-libs-4.11.3-40.el7.x86_64                                                                                                                                                                          1/14 
  正在更新    : rpm-4.11.3-40.el7.x86_64                                                                                                                                                                               2/14 
  正在更新    : rpm-build-libs-4.11.3-40.el7.x86_64                                                                                                                                                                    3/14 
  正在更新    : rpm-python-4.11.3-40.el7.x86_64                                                                                                                                                                        4/14 
  正在更新    : python-urlgrabber-3.10-9.el7.noarch                                                                                                                                                                    5/14 
  正在更新    : yum-3.4.3-163.el7.centos.noarch                                                                                                                                                                        6/14 
  正在更新    : yum-utils-1.1.31-52.el7.noarch                                                                                                                                                                         7/14 
  清理        : yum-utils-1.1.31-24.el7.noarch                                                                                                                                                                         8/14 
  清理        : yum-3.4.3-118.el7.centos.noarch                                                                                                                                                                        9/14 
  清理        : rpm-python-4.11.1-16.el7.x86_64                                                                                                                                                                       10/14 
  清理        : python-urlgrabber-3.10-4.el7.noarch                                                                                                                                                                   11/14 
  清理        : rpm-build-libs-4.11.1-16.el7.x86_64                                                                                                                                                                   12/14 
  清理        : rpm-libs-4.11.1-16.el7.x86_64                                                                                                                                                                         13/14 
  清理        : rpm-4.11.1-16.el7.x86_64                                                                                                                                                                              14/14 
  驗證中      : python-urlgrabber-3.10-9.el7.noarch                                                                                                                                                                    1/14 
  驗證中      : rpm-python-4.11.3-40.el7.x86_64                                                                                                                                                                        2/14 
  驗證中      : yum-utils-1.1.31-52.el7.noarch                                                                                                                                                                         3/14 
  驗證中      : rpm-4.11.3-40.el7.x86_64                                                                                                                                                                               4/14 
  驗證中      : yum-3.4.3-163.el7.centos.noarch                                                                                                                                                                        5/14 
  驗證中      : rpm-libs-4.11.3-40.el7.x86_64                                                                                                                                                                          6/14 
  驗證中      : rpm-build-libs-4.11.3-40.el7.x86_64                                                                                                                                                                    7/14 
  驗證中      : python-urlgrabber-3.10-4.el7.noarch                                                                                                                                                                    8/14 
  驗證中      : rpm-python-4.11.1-16.el7.x86_64                                                                                                                                                                        9/14 
  驗證中      : rpm-build-libs-4.11.1-16.el7.x86_64                                                                                                                                                                   10/14 
  驗證中      : rpm-libs-4.11.1-16.el7.x86_64                                                                                                                                                                         11/14 
  驗證中      : yum-utils-1.1.31-24.el7.noarch                                                                                                                                                                        12/14 
  驗證中      : yum-3.4.3-118.el7.centos.noarch                                                                                                                                                                       13/14 
  驗證中      : rpm-4.11.1-16.el7.x86_64                                                                                                                                                                              14/14 更新完畢:
  yum-utils.noarch 0:1.1.31-52.el7                                                                                                                                                                                          作為依賴被升級:
  python-urlgrabber.noarch 0:3.10-9.el7   rpm.x86_64 0:4.11.3-40.el7   rpm-build-libs.x86_64 0:4.11.3-40.el7   rpm-libs.x86_64 0:4.11.3-40.el7   rpm-python.x86_64 0:4.11.3-40.el7   yum.noarch 0:3.4.3-163.el7.centos  完畢!

新增下載地址:

yum-config-manager \     --add-repo \     

安裝DOCKER引擎

安裝最新版本的Docker Engine和容器,或轉到下一步以安裝特定版本: 過程比較漫長 等等就好

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

如果提示您接受GPG金鑰,請驗證指紋是否匹配 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35,如果是,則接受它。

不出意外 你會看到 成功兩個字 ,

啟動Docker。  systemctl start docker

別急 如果啟動失敗了 說明 版本問題導致的

你可以先解除安裝 再 繼續安裝 ,當然是選擇性安裝 根據版本號安裝

要安裝特定版本的Docker Engine,請在儲存庫中列出可用版本,然後選擇並安裝:

一個。列出並排序您儲存庫中可用的版本。此示例按版本號(從高到低)對結果進行排序,

[root@localhost lib]#  yum list docker-ce --showduplicates | sort -r已載入外掛:fastestmirror, langpacks可安裝的軟體包
 * updates: mirrors.aliyun.comLoading mirror speeds from cached hostfile
 * extras: mirrors.aliyun.comdocker-ce.x86_64            3:19.03.8-3.el7                     docker-ce-stabledocker-ce.x86_64            3:19.03.7-3.el7                     docker-ce-stabledocker-ce.x86_64            3:19.03.6-3.el7                     docker-ce-stabledocker-ce.x86_64            3:19.03.5-3.el7                     docker-ce-stabledocker-ce.x86_64            3:19.03.4-3.el7                     docker-ce-stabledocker-ce.x86_64            3:19.03.3-3.el7                     docker-ce-stabledocker-ce.x86_64            3:19.03.2-3.el7                     docker-ce-stabledocker-ce.x86_64            3:19.03.1-3.el7                     docker-ce-stabledocker-ce.x86_64            3:19.03.0-3.el7                     docker-ce-stabledocker-ce.x86_64            3:18.09.9-3.el7                     docker-ce-stabledocker-ce.x86_64            3:18.09.8-3.el7                     docker-ce-stabledocker-ce.x86_64            3:18.09.7-3.el7                     docker-ce-stabledocker-ce.x86_64            3:18.09.6-3.el7                     docker-ce-stabledocker-ce.x86_64            3:18.09.5-3.el7                     docker-ce-stabledocker-ce.x86_64            3:18.09.4-3.el7                     docker-ce-stabledocker-ce.x86_64            3:18.09.3-3.el7                     docker-ce-stabledocker-ce.x86_64            3:18.09.2-3.el7                     docker-ce-stabledocker-ce.x86_64            3:18.09.1-3.el7                     docker-ce-stabledocker-ce.x86_64            3:18.09.0-3.el7                     docker-ce-stabledocker-ce.x86_64            18.06.3.ce-3.el7                    docker-ce-stabledocker-ce.x86_64            18.06.2.ce-3.el7                    docker-ce-stabledocker-ce.x86_64            18.06.1.ce-3.el7                    docker-ce-stabledocker-ce.x86_64            18.06.0.ce-3.el7                    docker-ce-stabledocker-ce.x86_64            18.03.1.ce-1.el7.centos             docker-ce-stabledocker-ce.x86_64            18.03.0.ce-1.el7.centos             docker-ce-stabledocker-ce.x86_64            17.12.1.ce-1.el7.centos             docker-ce-stabledocker-ce.x86_64            17.12.0.ce-1.el7.centos             docker-ce-stabledocker-ce.x86_64            17.09.1.ce-1.el7.centos             docker-ce-stabledocker-ce.x86_64            17.09.0.ce-1.el7.centos             docker-ce-stabledocker-ce.x86_64            17.06.2.ce-1.el7.centos             docker-ce-stabledocker-ce.x86_64            17.06.1.ce-1.el7.centos             docker-ce-stabledocker-ce.x86_64            17.06.0.ce-1.el7.centos             docker-ce-stabledocker-ce.x86_64            17.03.3.ce-1.el7                    docker-ce-stabledocker-ce.x86_64            17.03.2.ce-1.el7.centos             docker-ce-stabledocker-ce.x86_64            17.03.1.ce-1.el7.centos             docker-ce-stabledocker-ce.x86_64            17.03.0.ce-1.el7.centos             docker-ce-stable
返回的列表取決於啟用了哪些儲存庫,並且特定於您的CentOS版本(.el7在本示例中以字尾表示)。b。透過其完全合格的軟體包名稱安裝特定版本,該軟體包名稱是軟體包名稱(docker-ce)加上版本字串(第二列),從第一個冒號(:)一直到第一個連字元,並用連字元(-)分隔。例如,docker-ce-18.09.1。yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io首先解除安裝之前的安裝 (當然你也可以選擇升級linux核心)yum remove docker-ce docker-ce-cli containerd.iorm -rf /var/lib/docker執行完成後繼續下面的執行

自定義安裝

[root@localhost ~]# yum install docker-ce-17.09.1.ceBDB2053 Freeing read locks for locker 0x72a: 51685/139945979692864已載入外掛:fastestmirror, langpacksLoading mirror speeds from cached hostfile
 * base: mirror.lzu.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com正在解決依賴關係--> 正在檢查事務---> 軟體包 docker-ce.x86_64.0.17.09.1.ce-1.el7.centos 將被 安裝--> 解決依賴關係完成依賴關係解決=============================================================================================================================================================================================================================================================================
 Package                                                      架構                                                      版本                                                                       源                                                                   大小=============================================================================================================================================================================================================================================================================正在安裝:
 docker-ce                                                    x86_64                                                    17.09.1.ce-1.el7.centos                                                    docker-ce-stable                                                     21 M事務概要=============================================================================================================================================================================================================================================================================安裝  1 軟體包總下載量:21 M安裝大小:21 MIs this ok [y/d/N]: yDownloading packages:docker-ce-17.09.1.ce-1.el7.cen FAILED                                                                                   91% [====================================================================================================          ]  1.2 B/s |  19 MB 433:07:05 ETA [Errno 12] Timeout on (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')正在嘗試其它映象。docker-ce-17.09.1.ce-1.el7.centos.x86_64.rpm                                                                                                                                                                                                          |  21 MB  00:00:56     Running transaction checkRunning transaction testTransaction test succeededRunning transaction
  正在安裝    : docker-ce-17.09.1.ce-1.el7.centos.x86_64                                                                                                                                                                                                                 1/1 
  驗證中      : docker-ce-17.09.1.ce-1.el7.centos.x86_64                                                                                                                                                                                                                 1/1 已安裝:
  docker-ce.x86_64 0:17.09.1.ce-1.el7.centos                                                                                                                                                                                                                                 完畢![root@localhost ~]# systemctl status docker.service ● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: failed (Result: start-limit) since 二 2020-04-07 21:52:23 CST; 41min ago
     Docs: 
 Main PID: 51154 (code=exited, status=1/FAILURE)4月 07 21:52:21 localhost.localdomain systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE4月 07 21:52:21 localhost.localdomain systemd[1]: Failed to start Docker Application Container Engine.4月 07 21:52:21 localhost.localdomain systemd[1]: Unit docker.service entered failed state.4月 07 21:52:21 localhost.localdomain systemd[1]: docker.service failed.4月 07 21:52:23 localhost.localdomain systemd[1]: docker.service holdoff time over, scheduling restart.4月 07 21:52:23 localhost.localdomain systemd[1]: Stopped Docker Application Container Engine.4月 07 21:52:23 localhost.localdomain systemd[1]: start request repeated too quickly for docker.service4月 07 21:52:23 localhost.localdomain systemd[1]: Failed to start Docker Application Container Engine.4月 07 21:52:23 localhost.localdomain systemd[1]: Unit docker.service entered failed state.4月 07 21:52:23 localhost.localdomain systemd[1]: docker.service failed.[root@localhost ~]# systemctl start docker.service [root@localhost ~]# [root@localhost ~]# [root@localhost ~]# systemctl status docker.service ● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: active (running) since 二 2020-04-07 22:33:51 CST; 8s ago
     Docs: 
 Main PID: 53799 (dockerd)
   Memory: 14.7M
   CGroup: /system.slice/docker.service
           ├─53799 /usr/bin/dockerd
           └─53805 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --shim docker-containerd-shim --runtime docker-runc4月 07 22:33:50 localhost.localdomain dockerd[53799]: time="2020-04-07T22:33:50.384733771+08:00" level=info msg="devmapper: Successfully created filesystem xfs on device docker-253:1-2180700-base"4月 07 22:33:50 localhost.localdomain dockerd[53799]: time="2020-04-07T22:33:50.460507062+08:00" level=info msg="Graph migration to content-addressability took 0.00 seconds"4月 07 22:33:50 localhost.localdomain dockerd[53799]: time="2020-04-07T22:33:50.460884311+08:00" level=warning msg="mountpoint for pids not found"4月 07 22:33:50 localhost.localdomain dockerd[53799]: time="2020-04-07T22:33:50.461183759+08:00" level=info msg="Loading containers: start."4月 07 22:33:50 localhost.localdomain dockerd[53799]: time="2020-04-07T22:33:50.901283597+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to set a preferred IP address"4月 07 22:33:51 localhost.localdomain dockerd[53799]: time="2020-04-07T22:33:51.123313352+08:00" level=info msg="Loading containers: done."4月 07 22:33:51 localhost.localdomain dockerd[53799]: time="2020-04-07T22:33:51.140985188+08:00" level=info msg="Docker daemon" commit=19e2cf6 graphdriver(s)=devicemapper version=17.09.1-ce4月 07 22:33:51 localhost.localdomain dockerd[53799]: time="2020-04-07T22:33:51.141114485+08:00" level=info msg="Daemon has completed initialization"4月 07 22:33:51 localhost.localdomain dockerd[53799]: time="2020-04-07T22:33:51.164127752+08:00" level=info msg="API listen on /var/run/docker.sock"4月 07 22:33:51 localhost.localdomain systemd[1]: Started Docker Application Container Engine.

然後執行示例程式 在這之前 需要引入國內的映象地址 

透過執行hello-world 映像來驗證是否正確安裝了Docker Engine 。

docker run hello-world

配置

/etc/docker 目錄下建立 daemon.json

[root@localhost docker]# ll總用量 8-rw-r--r-- 1 root root  65 4月   7 22:50 daemon.json-rw------- 1 root root 244 4月   7 22:33 key.json

然後裡面的內容為

{  "registry-mirrors": ["]  }

儲存後 執行 測試命令

[root@localhost docker]# docker run hello-worldUnable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete 
Digest: sha256:f9dfddf63636d84ef479d645ab5885156ae030f611a56f3a7ac7f2fdd86d7e4e
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 bashShare images, automate workflows, and more with a free Docker ID:
 
 /get-started/
[root@localhost docker]# docker run hello-worldHello 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 bashShare images, automate workflows, and more with a free Docker ID:
 
 /get-started/
[root@localhost docker]#

本文轉自:  https://blog.51cto.com/u_15446828/4775102


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/70003733/viewspace-2847598/,如需轉載,請註明出處,否則將追究法律責任。

相關文章