CentOS 7 安裝Docker
阿新 • • 發佈:2018-12-17
1、檢查環境 一)檢視CentOS版本
cat /etc/system-release
CentOS Linux release 7.3.1611 (Core)
二)檢視核心版本(需高於3.10)
uname -r
3.10.0-514.el7.x86_64
2、更新yum包(需root許可權)
sudo yum update
3、解除安裝舊版本(如果安裝過舊版本的話)
sudo yum remove docker docker-common docker-selinux docker-engine
4、安裝需要的軟體包 yum-util 提供yum-config-manager功能 另外兩個是devicemapper驅動依賴的
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
5、設定yum源
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror, langpacks 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
6、可以檢視所有倉庫中所有docker版本,並選擇特定版本安裝
yum list docker-ce --showduplicates | sort -r
7、安裝docker 一)、線上安裝* updates: mirrors.tuna.tsinghua.edu.cn Loading mirror speeds from cached hostfile Loaded plugins: fastestmirror, langpacks * extras: mirrors.tuna.tsinghua.edu.cn 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: mirrors.aliyun.com Available Packages
sudo yum install docker-ce
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.tuna.tsinghua.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
--> Running transaction check
---> Package container-selinux.noarch 2:2.68-1.el7 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
Transaction Summary
=======================================================================================================================================
Install 1 Package (+1 Dependent package)
Total download size: 41 M
Installed size: 41 M
Is this ok [y/d/N]: y
二)、離線安裝
wget ftp://ftp.pbone.net/mirror/ftp.scientificlinux.org/linux/scientific/7x/external_products/extras/x86_64/container-selinux-2.68-1.el7.noarch.rpm
wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-18.06.1.ce-3.el7.x86_64.rpm
[[email protected]_centos ~]# pwd
/root
[[email protected]_centos ~]# ll
-rw-r--r--. 1 root root 35676 10月 22 21:36 container-selinux-2.68-1.el7.noarch.rpm
-rw-r--r--. 1 root root 5888732 10月 22 21:41 docker-ce-18.06.1.ce-3.el7.x86_64.rpm
注意:需先安裝依賴!
rpm -ivh container-selinux-2.68-1.el7.noarch.rpm
警告:container-selinux-2.68-1.el7.noarch.rpm: 頭V4 DSA/SHA1 Signature, 金鑰 ID 192a7d7d: NOKEY
準備中... ################################# [100%]
正在升級/安裝...
1:container-selinux-2:2.68-1.el7 ################################# [100%]
rpm -ivh docker-ce-18.06.1.ce-3.el7.x86_64.rpm
警告:docker-ce-18.06.1.ce-3.el7.x86_64.rpm: 頭V4 RSA/SHA512 Signature, 金鑰 ID 621e9f35: NOKEY
準備中... ################################# [100%]
正在升級/安裝...
1:docker-ce-18.06.1.ce-3.el7 ################################# [100%]
8、啟動並加入開機啟動
sudo systemctl start docker
sudo systemctl enable docker
9、驗證安裝是否成功:先啟動docker服務 (有client和service兩部分表示docker安裝啟動都成功了)
[[email protected]_centos ~]# 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
10、啟用停用docker服務
systemctl stop docker.service
systemctl start docker.service
錯誤:
1、使用rpm安裝docker依賴丟擲如下錯誤
rpm -ivh container-selinux-2.68-1.el7.noarch.rpm
警告:container-selinux-2.68-1.el7.noarch.rpm: 頭V4 DSA/SHA1 Signature, 金鑰 ID 192a7d7d: NOKEY
錯誤:依賴檢測失敗:
policycoreutils-python 被 container-selinux-2:2.68-1.el7.noarch 需要
解決方法: 安裝policycoreutils-python即可 yum install policycoreutils-python