Docker 系列01: Centos7.3 上安裝docker


Docker從1.13版本之后采用時間線的方式作為版本號,分為社區版CE和企業版EE。

社區版是免費提供給個人開發者和小型團體使用的,企業版會提供額外的收費服務,比如經過官方測試認證過的基礎設施、容器、插件等。

社區版按照stable和edge兩種方式發布,每個季度更新stable版本,如17.06,17.09;每個月份更新edge版本,如17.09,17.10。

 一、安裝docker

1、Docker 要求 CentOS 系統的內核版本高於 3.10 ,查看本頁面的前提條件來驗證你的CentOS 版本是否支持 Docker 。

通過 uname -r 命令查看你當前的內核版本

uname -r

2、使用 root 權限登錄 Centos。確保 yum 包更新到最新。

yum update

3、卸載舊版本(如果安裝過舊版本的話)

yum -y  remove docker  docker-common docker-selinux docker-engine

4、安裝需要的軟件包, yum-util 提供yum-config-manager功能,另外兩個是devicemapper驅動依賴的

yum install -y yum-utils device-mapper-persistent-data lvm2

5、設置yum源

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum-config-manager  --add-repo  http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo #阿里雲yum源

 

6、可以查看所有倉庫中所有docker版本,並選擇特定版本安裝

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

7、安裝docker

yum install -y docker-ce  #由於repo中默認只開啟stable倉庫,故這里安裝的是最新穩定版17.12.0
yum install -y <FQPN> # 例如:sudo yum install docker-ce-17.12.0.ce

8、啟動並加入開機啟動

systemctl start docker
systemctl enable docker

9、驗證安裝是否成功(有client和service兩部分表示docker安裝啟動都成功了)

docker version

 二、問題

1、因為之前已經安裝過舊版本的docker,在安裝的時候報錯如下:

Transaction check error:
  file /usr/bin/docker from install of docker-ce-17.12.0.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64
  file /usr/bin/docker-containerd from install of docker-ce-17.12.0.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64
  file /usr/bin/docker-containerd-shim from install of docker-ce-17.12.0.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64
  file /usr/bin/dockerd from install of docker-ce-17.12.0.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64

2、卸載舊版本的包

yum erase docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64

l另外一種刪除docker的方法如下:

yum remove docker docker-common docker-selinux docker-engine -y
/etc/systemd -name '*docker*' -exec rm -f {} ;
find /etc/systemd -name '*docker*' -exec rm -f {} \;
find /lib/systemd -name '*docker*' -exec rm -f {} \;

 

3、再次安裝docker

yum install -y docker-ce

 

4、在step 2.7 docker-ce安裝過程中,可能會出現由於無法訪問repo源,或網速太慢無法安裝完成的問題

錯誤信息類似:

Dependencies Resolved

==========================================================================================================================================================================================
 Package                                     Arch                                  Version                                          Repository                                       Size
==========================================================================================================================================================================================
Installing:
 docker-ce                                   x86_64                                18.06.3.ce-3.el7                                 docker-ce-stable                                 41 M
Installing for dependencies:
 libtool-ltdl                                x86_64                                2.4.2-22.el7_3                                   base                                             49 k

Transaction Summary
==========================================================================================================================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 41 M
Installed size: 168 M
Is this ok [y/d/N]: y
Downloading packages:
(1/2): libtool-ltdl-2.4.2-22.el7_3.x86_64.rpm                                                                                                                      |  49 kB  00:00:05     
docker-ce-18.06.3.ce-3.el7.x86 FAILED                                          0% [                                                                    ]  6.7 B/s |  78 kB 1759:58:04 ETA 
https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/docker-ce-18.06.3.ce-3.el7.x86_64.rpm: [Errno 12] Timeout on https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/docker-ce-18.06.3.ce-3.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
docker-ce-18.06.3.ce-3.el7.x86 FAILED                                          0% [                                                                    ]  1.8 B/s | 112 kB 6558:40:59 ETA 
https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/docker-ce-18.06.3.ce-3.el7.x86_64.rpm: [Errno 12] Timeout on https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/docker-ce-18.06.3.ce-3.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
docker-ce-18.06.3.ce-3.el7.x86 FAILED                                          0% [                                                                    ]   11 B/s | 226 kB 1084:46:05 ETA 
https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/docker-ce-18.06.3.ce-3.el7.x86_64.rpm: [Errno 12] Timeout on https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/docker-ce-18.06.3.ce-3.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
(2/2): docker-ce-18.06.3.ce-3.el7.x86_64.rpm                                   0% [                                                                     ]  245 B

解決辦法:

用其他方式把rpm包下載下來,然后使用下面命令進行安裝

yum install -y *.rpm

參考的下載方法1:

只下載特定版本的rpm包到指定路徑,但是不安裝

yum install --downloadonly --downloaddir=/home/lenmom docker-ce-18.06.3.ce-3.el7
yum install --downloadonly --downloaddir=/home/lenmom libtool-ltdl-2.4.2-22.el7_3
yum install --downloadonly --downloaddir=/home/lenmom container-selinux-2.107-3.el7

 

參考下載方式2:

使用下載工具,如迅雷,下載指定的rpm包,下載地址可以在yum install 的輸出中找到

 

 

 

三、 配置阿里雲鏡像加速器

針對Docker客戶端版本大於1.10.0的用戶,可以通過修改daemon配置文件新版的 Docker 使用 /etc/docker/daemon.json(Linux) 或者 %programdata%\docker\config\daemon.json(Windows) 來使用加速器:    

1.創建文件夾(如存在無需重復創建)

mkdir  -p  /etc/docker
vi  /etc/docker/daemon.json 

添加以下內容:
 

{"registry-mirrors": 
["https://5f2jam6c.mirror.aliyuncs.com", 
"http://hub-mirror.c.163.com"]
}

 

2. 重新加載配置文件

systemctl reload  docker

3. 重啟Docker

systemctl restart docker

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM