官方文档: https://docs.docker.com/install/linux/docker-ce/centos/
CentOS 7 上安装 docker
#extras 源中包名为docker
[root@centos7 ~]#yum list docker
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Loading mirror speeds from cached hostfile
* base: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
Available Packages
docker.x86_64 2:1.13.1-103.git7f2769b.el7.centos
extras
下载rpm包安装:
官方rpm包下载地址:
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/
阿里镜像下载地址:
https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/
通过yum源安装:
由于官网的yum源太慢,下面使用阿里云的Yum源进行安装
rm -rf /etc/yum.repos.d/*
#CentOS 7 安装docker依赖三个yum源:Base,Extras,docker-ce
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-
ce/linux/centos/docker-ce.repo
yum clean all
yum -y install docker-ce
systemctl enable --now docker
删除 docker
[root@centos7 ~]#yum remove docker-ce
#删除docker资源存放的相关文件
[root@centos7 ~]#rm -rf /var/lib/docker
范例: CentOS 7 基于阿里云的安装docker方法
阿里云说明:
https://developer.aliyun.com/mirror/docker-ce?spm=a2c6h.13651102.0.0.3e221b11sUMKNV
# step 1: 安装必要的一些系统工具
yum install -y yum-utils device-mapper-persistent-data lvm2
# Step 2: 添加软件源信息
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-
ce/linux/centos/docker-ce.repo
# Step 3: 更新并安装Docker-CE
yum makecache fast
yum -y install docker-ce
# Step 4: 开启Docker服务
service docker start
# 注意:
# 官方软件源默认启用了最新的软件,您可以通过编辑软件源的方式获取各个版本的软件包。例如官方并没有
将测试版本的软件源置为可用,您可以通过以下方式开启。同理可以开启各种测试版本等。
# vim /etc/yum.repos.d/docker-ee.repo
# 将[docker-ce-test]下方的enabled=0修改为enabled=1
#
# 安装指定版本的Docker-CE:
# Step 1: 查找Docker-CE的版本:
# yum list docker-ce.x86_64 --showduplicates | sort -r
# Loading mirror speeds from cached hostfile
# Loaded plugins: branch, fastestmirror, langpacks
# docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-
stable
范例: 在CentOS 7上安装指定版本的docker
# 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
# Available Packages
# Step2: 安装指定版本的Docker-CE: (VERSION例如上面的17.03.0.ce.1-1.el7.centos)
yum -y install docker-ce-[VERSION]
#示例
[root@centos7 ~]#yum -y install docker-ce-19.03.12-3.el7
范例: 在CentOS 7上安装指定版本的docker
[root@centos7 ~]#cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@centos7 ~]# ls /etc/yum.repos.d/
backup base.repo
[root@centos7 ~]# wget -P /etc/yum.repos.d/ https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Saving to: ‘/etc/yum.repos.d/docker-ce.repo’
100%[====================================================================>]
2,640 --.-K/s in 0s
2020-01-23 21:56:21 (505 MB/s) - ‘/etc/yum.repos.d/docker-ce.repo’ saved
[2640/2640]
[root@centos7 ~]# ls /etc/yum.repos.d/
backup base.repo docker-ce.repo
[root@centos7 ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base docker-ce-stable epel extras
Cleaning up list of fastest mirrors
[root@centos7 ~]# yum repolist
repo id repo name
status
base CentOS
10,019
docker-ce-stable/x86_64 Docker CE Stable - x86_64
63
epel/7/x86_64 EPEL
13,513
extras/7/x86_64 extras
307
repolist: 23,902
[root@centos7 ~]# yum list docker-ce* --showduplicates | sort -r
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror
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
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
docker-ce-selinux.noarch 17.03.3.ce-1.el7 docker-ce-stable
docker-ce-selinux.noarch 17.03.2.ce-1.el7.centos docker-ce-stable
docker-ce-selinux.noarch 17.03.1.ce-1.el7.centos docker-ce-stable
docker-ce-selinux.noarch 17.03.0.ce-1.el7.centos docker-ce-stable
docker-ce-cli.x86_64 1:19.03.5-3.el7 docker-ce-stable
docker-ce-cli.x86_64 1:19.03.4-3.el7 docker-ce-stable
docker-ce-cli.x86_64 1:19.03.3-3.el7 docker-ce-stable
docker-ce-cli.x86_64 1:19.03.2-3.el7 docker-ce-stable
docker-ce-cli.x86_64 1:19.03.1-3.el7 docker-ce-stable
docker-ce-cli.x86_64 1:19.03.0-3.el7 docker-ce-stable
docker-ce-cli.x86_64 1:18.09.9-3.el7 docker-ce-stable
docker-ce-cli.x86_64 1:18.09.8-3.el7 docker-ce-stable
docker-ce-cli.x86_64 1:18.09.7-3.el7 docker-ce-stable
docker-ce-cli.x86_64 1:18.09.6-3.el7 docker-ce-stable
docker-ce-cli.x86_64 1:18.09.5-3.el7 docker-ce-stable
docker-ce-cli.x86_64 1:18.09.4-3.el7 docker-ce-stable
docker-ce-cli.x86_64 1:18.09.3-3.el7 docker-ce-stable
docker-ce-cli.x86_64 1:18.09.2-3.el7 docker-ce-stable
docker-ce-cli.x86_64 1:18.09.1-3.el7 docker-ce-stable
docker-ce-cli.x86_64 1:18.09.0-3.el7 docker-ce-stable
Available Packages
[root@centos7 ~]# yum -y install docker-ce-18.09.9-3.el7 docker-ce-cli-18.09.9-3.el7
Dependencies Resolved
================================================================================
=========
Package Arch Version
Repository Size
================================================================================
Installing:
docker-ce x86_64 3:18.09.9-3.el7
docker-ce-stable 21 M
docker-ce-cli x86_64 1:18.09.9-3.el7
docker-ce-stable 16 M
Installing for dependencies:
audit-libs-python x86_64 2.8.4-4.el7
base 76 k
checkpolicy x86_64 2.5-8.el7
base 295 k
container-selinux noarch 2:2.107-3.el7
extras 39 k
containerd.io x86_64 1.2.10-3.2.el7
docker-ce-stable 23 M
libcgroup x86_64 0.41-20.el7
base 66 k
libsemanage-python x86_64 2.5-14.el7
base 113 k
policycoreutils-python x86_64 2.5-29.el7
base 456 k
python-IPy noarch 0.75-6.el7
base 32 k
setools-libs x86_64 3.3.8-4.el7
base 620 k
Transaction Summary
======================================================================
==============================
Install 2 Packages (+9 Dependent packages)
Total download size: 62 M
Installed size: 258 M
Downloading packages:
(1/4): container-selinux-2.107-3.el7.noarch.rpm
| 39 kB 00:00:00
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/containerd.io-1.2.10-
3.2.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
Public key for containerd.io-1.2.10-3.2.el7.x86_64.rpm is not installed
(2/4): containerd.io-1.2.10-3.2.el7.x86_64.rpm
| 23 MB 00:00:03
(3/4): docker-ce-18.09.9-3.el7.x86_64.rpm
| 21 MB 00:00:04
(4/4): docker-ce-cli-18.09.9-3.el7.x86_64.rpm
| 16 MB 00:00:01
Complete!
[root@centos7 ~]# docker version
Client:
Version: 18.09.9
API version: 1.39
Go version: go1.11.13
Git commit: 039a7df9ba
Built: Wed Sep 4 16:51:21 2019
OS/Arch: linux/amd64
Experimental: false
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the
docker daemon running?
[root@centos7 ~]# systemctl enable --now docker
[root@centos7 ~]# docker version
Client:
Version: 18.09.9
Go version: go1.11.13
Git commit: 039a7df
Built: Wed Sep 4 16:22:32 2019
OS/Arch: linux/amd64
Experimental: false
[root@centos7 ~]#
范例: 在CentOS8安装docker
[root@centos8 ~]#tee /etc/yum.repos.d/docker.repo <
[docker]
name=docker
gpgcheck=0
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/8/x86_64/stable/
EOF
[root@centos8 ~]#dnf -y install docker-ce