0.卸载旧版本
较旧的 Docker 版本称为 docker 或 docker-engine 。如果已安装这些程序,请卸载它们以及相关的依赖项。
#yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
1.准备:安装所需的软件包。yum-utils 提供了 yum-config-manager ,并且 device mapper 存储驱动程序需要 device-mapper-persistent-data 和 lvm2。
[root@centos7 ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
epel/x86_64/metalink | 8.2 kB 00:00
- base: mirrors.aliyun.com
- epel: mirrors.aliyun.com
- extras: mirrors.aliyun.com
- updates: mirrors.aliyun.com
base | 3.6 kB 00:00
epel | 5.3 kB 00:00
extras | 2.9 kB 00:00
updates | 2.9 kB 00:00
(1/2): epel/x86_64/updateinfo | 1.0 MB 00:02
(2/2): epel/x86_64/primary_db | 6.9 MB 00:03
软件包 yum-utils-1.1.31-52.el7.noarch 已安装并且是最新版本
软件包 device-mapper-persistent-data-0.8.5-1.el7.x86_64 已安装并且是最新版本
软件包 7:lvm2-2.02.185-2.el7_7.2.x86_64 已安装并且是最新版本
无须任何处理
2.使用以下命令来设置稳定的仓库。
[root@centos7 ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
已加载插件: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
- [root@centos7 ~]#yum-config-manager --enable docker-ce-edge(开启docker-ce-edge源)
已加载插件:fastestmirror, langpacks
============================= repo: docker-ce-edge =============================
[docker-ce-edge]
async = True
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/7
baseurl = https://download.docker.com/linux/centos/7/x86_64/edge
cache = 0
cachedir = /var/cache/yum/x86_64/7/docker-ce-edge
check_config_file_age = True
compare_providers_priority = 80
cost = 1000
deltarpm_metadata_percentage = 100
deltarpm_percentage =
enabled = 1
enablegroups = True
exclude =
failovermethod = priority
ftp_disable_epsv = False
gpgcadir = /var/lib/yum/repos/x86_64/7/docker-ce-edge/gpgcadir
gpgcakey =
gpgcheck = True
gpgdir = /var/lib/yum/repos/x86_64/7/docker-ce-edge/gpgdir
gpgkey = https://download.docker.com/linux/centos/gpg
hdrdir = /var/cache/yum/x86_64/7/docker-ce-edge/headers
http_caching = all
includepkgs =
ip_resolve =
keepalive = True
keepcache = False
mddownloadpolicy = sqlite
mdpolicy = group:small
mediaid =
metadata_expire = 21600
metadata_expire_filter = read-only:present
metalink =
minrate = 0
mirrorlist =
mirrorlist_expire = 86400
name = Docker CE Edge - x86_64
old_base_cache_dir =
password =
persistdir = /var/lib/yum/repos/x86_64/7/docker-ce-edge
pkgdir = /var/cache/yum/x86_64/7/docker-ce-edge/packages
proxy = False
proxy_dict =
proxy_password =
proxy_username =
repo_gpgcheck = False
retries = 10
skip_if_unavailable = False
ssl_check_cert_permissions = True
sslcacert =
sslclientcert =
sslclientkey =
sslverify = True
throttle = 0
timeout = 30.0
ui_id = docker-ce-edge/x86_64
ui_repoid_vars = releasever,
basearch
username =
4.[root@centos7 ~]#yum-config-manager --enable docker-ce-test(可不开启)
已加载插件:fastestmirror, langpacks
============================= repo: docker-ce-test =============================
[docker-ce-test]
async = True
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/7
baseurl = https://download.docker.com/linux/centos/7/x86_64/test
cache = 0
cachedir = /var/cache/yum/x86_64/7/docker-ce-test
check_config_file_age = True
compare_providers_priority = 80
cost = 1000
deltarpm_metadata_percentage = 100
deltarpm_percentage =
enabled = 1
enablegroups = True
exclude =
failovermethod = priority
ftp_disable_epsv = False
gpgcadir = /var/lib/yum/repos/x86_64/7/docker-ce-test/gpgcadir
gpgcakey =
gpgcheck = True
gpgdir = /var/lib/yum/repos/x86_64/7/docker-ce-test/gpgdir
gpgkey = https://download.docker.com/linux/centos/gpg
hdrdir = /var/cache/yum/x86_64/7/docker-ce-test/headers
http_caching = all
includepkgs =
ip_resolve =
keepalive = True
keepcache = False
mddownloadpolicy = sqlite
mdpolicy = group:small
mediaid =
metadata_expire = 21600
metadata_expire_filter = read-only:present
metalink =
minrate = 0
mirrorlist =
mirrorlist_expire = 86400
name = Docker CE Test - x86_64
old_base_cache_dir =
password =
persistdir = /var/lib/yum/repos/x86_64/7/docker-ce-test
pkgdir = /var/cache/yum/x86_64/7/docker-ce-test/packages
proxy = False
proxy_dict =
proxy_password =
proxy_username =
repo_gpgcheck = False
retries = 10
skip_if_unavailable = False
ssl_check_cert_permissions = True
sslcacert =
sslclientcert =
sslclientkey =
sslverify = True
throttle = 0
timeout = 30.0
ui_id = docker-ce-test/x86_64
ui_repoid_vars = releasever,
basearch
username =
5.[root@centos7 ~]#yum makecache fast(更新缓存,源立即生效)
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
epel/x86_64/metalink | 8.2 kB 00:00
- base: mirrors.aliyun.com
- epel: mirrors.aliyun.com
- extras: mirrors.aliyun.com
- updates: mirrors.aliyun.com
base | 3.6 kB 00:00
docker-ce-edge | 3.5 kB 00:00
docker-ce-stable | 3.5 kB 00:00
docker-ce-test | 3.5 kB 00:00
epel | 5.3 kB 00:00
extras | 2.9 kB 00:00
updates | 2.9 kB 00:00
(1/6): docker-ce-stable/x86_64/updateinfo | 55 B 00:01
(2/6): docker-ce-test/x86_64/updateinfo | 55 B 00:01
(3/6): docker-ce-test/x86_64/primary_db | 110 kB 00:00
(4/6): docker-ce-stable/x86_64/primary_db | 37 kB 00:01
(5/6): docker-ce-edge/x86_64/updateinfo | 55 B 00:01
(6/6): docker-ce-edge/x86_64/primary_db | 41 kB 00:01
元数据缓存已建立
6.安装 Docker Engine-Community
6.1要安装特定版本的 Docker Engine-Community
6.1.1列出并排序您存储库中可用的版本。此示例按版本号(从高到低)对结果进行排序。
[root@centos7 ~]#yum list docker-ce –showduplicates | sort -r
已加载插件:fastestmirror, langpacks
已安装的软件包
可安装的软件包 - updates: mirrors.aliyun.com
Loading mirror speeds from cached hostfile - extras: mirrors.aliyun.com
- epel: mirrors.aliyun.com
docker-ce.x86_64 3:19.03.5-3.el7 docker-ce-test
docker-ce.x86_64 3:19.03.5-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.5-3.el7 docker-ce-edge
docker-ce.x86_64 3:19.03.5-3.el7 @docker-ce-edge
docker-ce.x86_64 3:19.03.5-2.1.rc1.el7 docker-ce-test
docker-ce.x86_64 3:19.03.5-1.2.beta2.el7 docker-ce-test
docker-ce.x86_64 3:19.03.5-1.1.beta1.el7 docker-ce-test
docker-ce.x86_64 3:19.03.4-3.el7 docker-ce-test
docker-ce.x86_64 3:19.03.4-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.4-3.el7 docker-ce-edge
docker-ce.x86_64 3:19.03.4-2.1.rc1.el7 docker-ce-test
docker-ce.x86_64 3:19.03.3-3.el7 docker-ce-test
docker-ce.x86_64 3:19.03.3-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.3-3.el7 docker-ce-edge
docker-ce.x86_64 3:19.03.3-2.1.rc1.el7 docker-ce-test
docker-ce.x86_64 3:19.03.3-1.2.beta2.el7 docker-ce-test
docker-ce.x86_64 3:19.03.3-1.1.beta1.el7 docker-ce-test
docker-ce.x86_64 3:19.03.2-3.el7 docker-ce-test
docker-ce.x86_64 3:19.03.2-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.2-3.el7 docker-ce-edge
docker-ce.x86_64 3:19.03.2-2.1.rc1.el7 docker-ce-test
docker-ce.x86_64 3:19.03.2-1.1.beta1.el7 docker-ce-test
docker-ce.x86_64 3:19.03.1-3.el7 docker-ce-test
docker-ce.x86_64 3:19.03.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.1-3.el7 docker-ce-edge
docker-ce.x86_64 3:19.03.0-3.el7 docker-ce-test
docker-ce.x86_64 3:19.03.0-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.0-3.el7 docker-ce-edge
docker-ce.x86_64 3:19.03.0-2.3.rc3.el7 docker-ce-test
docker-ce.x86_64 3:19.03.0-2.2.rc2.el7 docker-ce-test
docker-ce.x86_64 3:19.03.0-1.5.beta5.el7 docker-ce-test
docker-ce.x86_64 3:19.03.0-1.4.beta4.el7 docker-ce-test
docker-ce.x86_64 3:19.03.0-1.3.beta3.el7 docker-ce-test
docker-ce.x86_64 3:19.03.0-1.2.beta2.el7 docker-ce-test
docker-ce.x86_64 3:19.03.0-1.1.beta1.el7 docker-ce-test
…
docker-ce.x86_64 17.03.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.2.ce-0.1.rc1.el7.centos docker-ce-test
docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.1.ce-0.1.rc1.el7.centos docker-ce-test
docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable
- base: mirrors.aliyun.com
6.1.2通过其完整的软件包名称安装特定版本,该软件包名称是软件包名称(docker-ce)加上版本字符串(第二列),从第一个冒号(:)一直到第一个连字符,并用连字符(-)分隔。例如:docker-ce-18.09.1。
#yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
6.2安装最新版本的 Docker Engine-Community 和 containerd
[root@centos7 ~]#yum install docker-ce (docker-ce-cli containerd.io)
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile - base: mirrors.aliyun.com
- epel: mirrors.aliyun.com
- extras: mirrors.aliyun.com
- updates: mirrors.aliyun.com
正在解决依赖关系
–> 正在检查事务
—> 软件包 docker-ce.x86_64.3.19.03.5-3.el7 将被 安装
–> 正在处理依赖关系 container-selinux >= 2:2.74,它被软件包 3:docker-ce-19.03.5-3.el7.x86_64 需要
–> 正在处理依赖关系 containerd.io >= 1.2.2-3,它被软件包 3:docker-ce-19.03.5-3.el7.x86_64 需要
–> 正在处理依赖关系 docker-ce-cli,它被软件包 3:docker-ce-19.03.5-3.el7.x86_64 需要
–> 正在检查事务
—> 软件包 container-selinux.noarch.2.2.107-3.el7 将被 安装
—> 软件包 containerd.io.x86_64.0.1.2.10-3.2.el7 将被 安装
—> 软件包 docker-ce-cli.x86_64.1.19.03.5-3.el7 将被 安装
–> 解决依赖关系完成
…
总计 2.0 MB/s | 87 MB 00:43
从 https://download.docker.com/linux/centos/gpg 检索密钥
导入 GPG key 0x621E9F35:
用户ID : “Docker Release (CE rpm) docker@docker.com”
指纹 : 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
来自 : https://download.docker.com/linux/centos/gpg
是否继续?[y/N]:y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : 2:container-selinux-2.107-3.el7.noarch 1/4
正在安装 : containerd.io-1.2.10-3.2.el7.x86_64 2/4
正在安装 : 1:docker-ce-cli-19.03.5-3.el7.x86_64 3/4
正在安装 : 3:docker-ce-19.03.5-3.el7.x86_64 4/4
验证中 : containerd.io-1.2.10-3.2.el7.x86_64 1/4
验证中 : 1:docker-ce-cli-19.03.5-3.el7.x86_64 2/4
验证中 : 2:container-selinux-2.107-3.el7.noarch 3/4
验证中 : 3:docker-ce-19.03.5-3.el7.x86_64 4/4
已安装:
docker-ce.x86_64 3:19.03.5-3.el7
作为依赖被安装:
container-selinux.noarch 2:2.107-3.el7 containerd.io.x86_64 0:1.2.10-3.2.el7
docker-ce-cli.x86_64 1:19.03.5-3.el7
完毕!
7.[root@centos7 ~]#systemctl start docker
[root@centos7 ~]#systemctl enable docker
[root@centos7 ~]#systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since 二 2019-12-03 17:03:31 CST; 9s ago
Docs: https://docs.docker.com
Main PID: 29576 (dockerd)
Tasks: 10
Memory: 55.8M
CGroup: /system.slice/docker.service
└─29576 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/con…
12月 03 17:03:09 centos7.cqdzzx.cn dockerd[29576]: time="2019-12-03T17:03:09…
12月 03 17:03:09 centos7.cqdzzx.cn dockerd[29576]: time="2019-12-03T17:03:09…
12月 03 17:03:09 centos7.cqdzzx.cn dockerd[29576]: time="2019-12-03T17:03:09…
12月 03 17:03:09 centos7.cqdzzx.cn dockerd[29576]: time="2019-12-03T17:03:09…
12月 03 17:03:15 centos7.cqdzzx.cn dockerd[29576]: time="2019-12-03T17:03:15…
12月 03 17:03:19 centos7.cqdzzx.cn dockerd[29576]: time="2019-12-03T17:03:19…
12月 03 17:03:29 centos7.cqdzzx.cn dockerd[29576]: time="2019-12-03T17:03:29…
12月 03 17:03:29 centos7.cqdzzx.cn dockerd[29576]: time="2019-12-03T17:03:29…
12月 03 17:03:31 centos7.cqdzzx.cn systemd[1]: Started Docker Application C…
12月 03 17:03:31 centos7.cqdzzx.cn dockerd[29576]: time="2019-12-03T17:03:31…
Hint: Some lines were ellipsized, use -l to show in full.
8.测试
#docker run hello-world
Unable to find image ‘hello-world:latest’ locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:4df8ca8a7e309c256d60d7971ea14c27672fc0d10c5f303856d7bc48f8cc17ff
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
- The Docker client contacted the Docker daemon.
- The Docker daemon pulled the “hello-world” image from the Docker Hub.
(amd64) - The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading. - The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
9.设置加速
对于CentOS7 ,为docker设置加速可这样做:
vim /etc/docker/daemon.json
输入以下内容:
{
“registry-mirrors”:[“https://6kx4zyno.mirror.aliyuncs.com”]
}
保存退出后,再重启docker。