CentOS7.4下搭建docker環境
阿新 • • 發佈:2018-11-23
Docker從1.13版本之後採用時間線的方式作為版本號,分為社群版CE和企業版EE。
社群版是免費提供給個人開發者和小型團體使用的,企業版會提供額外的收費服務,比如經過官方測試認證過的基礎設施、容器、外掛等。
社群版按照stable和edge兩種方式釋出,每個季度更新stable版本,如18.03,18.06;每個月份更新edge版本,如18.06,18.07。
Docker安裝
- Docker 要求 CentOS 系統的核心版本高於 3.10 ,檢視本頁面的前提條件來驗證你的CentOS 版本是否支援 Docker 。
通過 uname -r 命令檢視你當前的核心版本
[[email protected]0002 ~]# uname -r
3.10.0-693.11.1.el7.x86_64
- 使用 root 許可權登入 Centos。確保 yum 包更新到最新。
[[email protected]-a30e-0002 ~]# yum update
- 解除安裝舊版本(如果安裝過舊版本的話)
[[email protected]-a30e-0002 ~]# yum remove docker docker-common docker-selinux docker-engine
- 安裝需要的軟體包, yum-util 提供yum-config-manager功能,另外兩個是devicemapper驅動依賴的
[[email protected]-a30e-0002 ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
- 設定docker的yum源
[[email protected]0002 ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
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
- 可以檢視所有倉庫中所有docker版本,並選擇特定版本安裝
[[email protected]0002 ~]# yum list docker-ce --showduplicates | sort -r
* updates: mirror.bit.edu.cn
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror
* extras: mirrors.huaweicloud.com
* epel: mirrors.huaweicloud.com
docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 18.03.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.12.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.12.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.09.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.09.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.3.ce-1.el7 docker-ce-stable
docker-ce.x86_64 17.03.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable
* base: mirror.bit.edu.cn
Available Packages
- 安裝docker
$ sudo yum install docker-ce #由於repo中預設只開啟stable倉庫,故這裡安裝的是最新穩定版17.12.0
[[email protected]0002 ~]# yum install docker-ce
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.bit.edu.cn
* epel: mirrors.huaweicloud.com
* extras: mirrors.huaweicloud.com
* updates: mirror.bit.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 0:18.06.1.ce-3.el7 will be installed
--> Processing Dependency: container-selinux >= 2.9 for package: docker-ce-18.06.1.ce-3.el7.x86_64
--> Processing Dependency: libseccomp >= 2.3 for package: docker-ce-18.06.1.ce-3.el7.x86_64
--> Processing Dependency: libseccomp.so.2()(64bit) for package: docker-ce-18.06.1.ce-3.el7.x86_64
--> Processing Dependency: libltdl.so.7()(64bit) for package: docker-ce-18.06.1.ce-3.el7.x86_64
--> Running transaction check
---> Package container-selinux.noarch 2:2.68-1.el7 will be installed
---> Package libseccomp.x86_64 0:2.3.1-3.el7 will be installed
---> Package libtool-ltdl.x86_64 0:2.4.2-22.el7_3 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
====================================================================================================================================================================
Package Arch Version Repository Size
====================================================================================================================================================================
Installing:
docker-ce x86_64 18.06.1.ce-3.el7 docker-ce-stable 41 M
Installing for dependencies:
container-selinux noarch 2:2.68-1.el7 extras 36 k
libseccomp x86_64 2.3.1-3.el7 base 56 k
libtool-ltdl x86_64 2.4.2-22.el7_3 base 49 k
Transaction Summary
====================================================================================================================================================================
Install 1 Package (+3 Dependent packages)
Total download size: 41 M
Installed size: 41 M
Is this ok [y/d/N]: y
Downloading packages:
(1/4): container-selinux-2.68-1.el7.noarch.rpm | 36 kB 00:00:00
(2/4): libtool-ltdl-2.4.2-22.el7_3.x86_64.rpm | 49 kB 00:00:00
(3/4): libseccomp-2.3.1-3.el7.x86_64.rpm | 56 kB 00:00:00
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-18.06.1.ce-3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY0:00:00 ETA
Public key for docker-ce-18.06.1.ce-3.el7.x86_64.rpm is not installed
(4/4): docker-ce-18.06.1.ce-3.el7.x86_64.rpm | 41 MB 00:13:30
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 52 kB/s | 41 MB 00:13:30
Retrieving key from https://download.docker.com/linux/centos/gpg
Importing GPG key 0x621E9F35:
Userid : "Docker Release (CE rpm) <[email protected]>"
Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
From : https://download.docker.com/linux/centos/gpg
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : libseccomp-2.3.1-3.el7.x86_64 1/4
Installing : 2:container-selinux-2.68-1.el7.noarch 2/4
setsebool: SELinux is disabled.
Installing : libtool-ltdl-2.4.2-22.el7_3.x86_64 3/4
Installing : docker-ce-18.06.1.ce-3.el7.x86_64 4/4
Verifying : docker-ce-18.06.1.ce-3.el7.x86_64 1/4
Verifying : libtool-ltdl-2.4.2-22.el7_3.x86_64 2/4
Verifying : 2:container-selinux-2.68-1.el7.noarch 3/4
Verifying : libseccomp-2.3.1-3.el7.x86_64 4/4
Installed:
docker-ce.x86_64 0:18.06.1.ce-3.el7
Dependency Installed:
container-selinux.noarch 2:2.68-1.el7 libseccomp.x86_64 0:2.3.1-3.el7 libtool-ltdl.x86_64 0:2.4.2-22.el7_3
Complete!
- 啟動並加入開機啟動
[root@ecs-a30e-0002 ~]# systemctl start docker
[root@ecs-a30e-0002 ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
- 驗證安裝是否成功(有client和service兩部分表示docker安裝啟動都成功了)
[root@ecs-a30e-0002 ~]# docker version
Client:
Version: 18.06.1-ce
API version: 1.38
Go version: go1.10.3
Git commit: e68fc7a
Built: Tue Aug 21 17:23:03 2018
OS/Arch: linux/amd64
Experimental: false
Server:
Engine:
Version: 18.06.1-ce
API version: 1.38 (minimum version 1.12)
Go version: go1.10.3
Git commit: e68fc7a
Built: Tue Aug 21 17:25:29 2018
OS/Arch: linux/amd64
Experimental: false
所有安裝方法參考自這裡,我是邊安裝邊記錄