容器技術之Centos8安裝Docker

容器技術之Centos8安裝Docker

一、Docker簡介

Docker的手冊:https://docs.docker.com/install/linux/docker-ce/centos/

Docker 是一個開源/246339)的應用容器引擎,讓開發者可以打包他們的應用以及依賴包到一個可移植的鏡像中,然後發佈到任何流行的 Linux或Windows 機器上,也可以實現虛擬化。容器是完全使用沙箱機制,相互之間不會有任何接口。

二、Docker的安裝

2.1. 刪除舊的Docker

[root@localhost ~]#  yum remove docker docker-common docker-selinux docker-engine
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository AppStream is listed more than once in the configuration
未找到匹配的參數: docker
未找到匹配的參數: docker-common
未找到匹配的參數: docker-selinux
未找到匹配的參數: docker-engine
沒有軟件包需要移除。
依賴關係解決。
無需任何處理。
完畢!

2.2. 安裝相關依賴

[root@localhost ~]# yum install -y yum-utils \
>   device-mapper-persistent-data \
>   lvm2
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository AppStream is listed more than once in the configuration
CentOS-8 - Base                                                                                               3.3 MB/s | 4.0 MB     00:01    
Extra Packages for Enterprise Linux Modular 8 - x86_64                                                        7.9 kB/s |  13 kB     00:01    
軟件包 device-mapper-persistent-data-0.8.5-2.el8.x86_64 已安裝。
軟件包 lvm2-8:2.03.05-5.el8.0.1.x86_64 已安裝。
依賴關係解決。
==============================================================================================================================================
 軟件包                            架構                           版本                                   倉庫                            大小
==============================================================================================================================================
安裝:
 yum-utils                         noarch                         4.0.8-3.el8                            BaseOS                          64 k

事務概要
==============================================================================================================================================
安裝  1 軟件包

總下載:64 k
安裝大小:19 k
下載軟件包:
yum-utils-4.0.8-3.el8.noarch.rpm                                                                              295 kB/s |  64 kB     00:00    
----------------------------------------------------------------------------------------------------------------------------------------------
總計                                                                                                           87 kB/s |  64 kB     00:00     
運行事務檢查
事務檢查成功。
運行事務測試
事務測試成功。
運行事務
  準備中  :                                                                                                                               1/1 
  安裝    : yum-utils-4.0.8-3.el8.noarch                                                                                                  1/1 
  運行腳本: yum-utils-4.0.8-3.el8.noarch                                                                                                  1/1 
  驗證    : yum-utils-4.0.8-3.el8.noarch                                                                                                  1/1 

已安裝:
  yum-utils-4.0.8-3.el8.noarch                                                                                                                

完畢!

2.3. 查看Docker版本

[root@localhost ~]# yum list docker-ce --showduplicates | sort -r
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository AppStream is listed more than once in the configuration
Extra Packages for Enterprise Linux Modular 8 - 6.1 kB/s | 9.4 kB     00:01    
Extra Packages for Enterprise Linux 8 - x86_64  6.5 kB/s |  10 kB     00:01    
docker-ce.x86_64            3:19.03.5-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.4-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.3-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.2-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.1-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.0-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.9-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.8-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.7-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.6-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.5-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.4-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.3-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.2-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.1-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.0-3.el7                     docker-ce-stable
docker-ce.x86_64            18.06.3.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.06.2.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.06.1.ce-3.el7                    docker-ce-stable

2.4. 安裝Docker

這是安裝可能會報錯

[root@localhost ~]# yum install docker-ce
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository AppStream is listed more than once in the configuration
上次元數據過期檢查:0:00:38 前,執行於 2020年01月28日 星期二 17時02分33秒。
錯誤:
 問題: package docker-ce-3:19.03.5-3.el7.x86_64 requires containerd.io >= 1.2.2-3, but none of the providers can be installed
  - cannot install the best candidate for the job
  - package containerd.io-1.2.10-3.2.el7.x86_64 is excluded
  - package containerd.io-1.2.2-3.3.el7.x86_64 is excluded
  - package containerd.io-1.2.2-3.el7.x86_64 is excluded
  - package containerd.io-1.2.4-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.5-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.6-3.3.el7.x86_64 is excluded
(嘗試添加 '--skip-broken' 來跳過無法安裝的軟件包 或 '--nobest' 來不只使用最佳選擇的軟件包)

這個時候需要安裝containerd.io,我們可以到這個網站https://download.docker.com/linux/centos/7/x86_64/stable/Packages/,找到最新的去安裝

[root@localhost ~]# dnf install https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm

繼續進行安裝

[root@localhost ~]# yum install docker-ce docker-ce-cli

2.5. 啓動Docker,並設置爲開機自啓

[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl enable docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.

三、Docker-compose安裝

因爲Centos8就安裝了Python3pip3,所以直接安裝就可以了。我在Centos7pip2安裝docker-compose死活裝不上,真的扎心!

[root@localhost ~]# pip3 -V
pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)
[root@localhost ~]# pip3 install docker-compose
[root@localhost ~]# docker-compose version
docker-compose version 1.25.3, build unknown
docker-py version: 4.1.0
CPython version: 3.6.8
OpenSSL version: OpenSSL 1.1.1c FIPS  28 May 2019
[root@localhost ~]# 

四、修改Docker下載源

登錄阿里雲:https://cr.console.aliyun.com/cn-hangzhou/mirrors。最後一欄就是鏡像加速器。會有自己的鏡像加速器地址。

選擇Centos進行執行:

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://xxxxx.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

五、歡迎關注下公衆號

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章