本文参照:
Centos7 安装 docker
https://blog.csdn.net/mshxuyi/article/details/108209796
环境:
本地windows10,VMware? Workstation 12 Pro
CentOS-7-x86_64
SecureCRT
1、删除 旧版本 docker
rpm -qa | grep docker
# 结果
docker-common-1.13.1-162.git64e9980.el7.centos.x86_64
docker-client-1.13.1-162.git64e9980.el7.centos.x86_64
docker-1.13.1-162.git64e9980.el7.centos.x86_64
# 删除
yum remove docker docker-common docker-client
[root@localhost ~]# rpm -qa | grep docker
[root@localhost ~]#
2、安装需要的软件包
yum install -y yum-utils device-mapper-persistent-data lvm2
[root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.ustc.edu.cn
* updates: mirrors.ustc.edu.cn
软件包 yum-utils-1.1.31-54.el7_8.noarch 已安装并且是最新版本
正在解决依赖关系
--> 正在检查事务
---> 软件包 device-mapper-persistent-data.x86_64.0.0.8.5-3.el7 将被 升级
---> 软件包 device-mapper-persistent-data.x86_64.0.0.8.5-3.el7_9.2 将被 更新
---> 软件包 lvm2.x86_64.7.2.02.187-6.el7 将被 升级
---> 软件包 lvm2.x86_64.7.2.02.187-6.el7_9.3 将被 更新
--> 正在处理依赖关系 lvm2-libs = 7:2.02.187-6.el7_9.3,它被软件包 7:lvm2-2.02.187-6.el7_9.3.x86_64 需要
--> 正在检查事务
---> 软件包 lvm2-libs.x86_64.7.2.02.187-6.el7 将被 升级
---> 软件包 lvm2-libs.x86_64.7.2.02.187-6.el7_9.3 将被 更新
--> 正在处理依赖关系 device-mapper-event = 7:1.02.170-6.el7_9.3,它被软件包 7:lvm2-libs-2.02.187-6.el7_9.3.x86_64 需要
--> 正在检查事务
---> 软件包 device-mapper-event.x86_64.7.1.02.170-6.el7 将被 升级
---> 软件包 device-mapper-event.x86_64.7.1.02.170-6.el7_9.3 将被 更新
--> 正在处理依赖关系 device-mapper-event-libs = 7:1.02.170-6.el7_9.3,它被软件包 7:device-mapper-event-1.02.170-6.el7_9.3.x86_64 需要
--> 正在处理依赖关系 device-mapper = 7:1.02.170-6.el7_9.3,它被软件包 7:device-mapper-event-1.02.170-6.el7_9.3.x86_64 需要
--> 正在检查事务
---> 软件包 device-mapper.x86_64.7.1.02.170-6.el7 将被 升级
--> 正在处理依赖关系 device-mapper = 7:1.02.170-6.el7,它被软件包 7:device-mapper-libs-1.02.170-6.el7.x86_64 需要
---> 软件包 device-mapper.x86_64.7.1.02.170-6.el7_9.3 将被 更新
---> 软件包 device-mapper-event-libs.x86_64.7.1.02.170-6.el7 将被 升级
---> 软件包 device-mapper-event-libs.x86_64.7.1.02.170-6.el7_9.3 将被 更新
--> 正在检查事务
---> 软件包 device-mapper-libs.x86_64.7.1.02.170-6.el7 将被 升级
---> 软件包 device-mapper-libs.x86_64.7.1.02.170-6.el7_9.3 将被 更新
--> 解决依赖关系完成
依赖关系解决
=============================================================================================================================================================================================
Package 架构 版本 源 大小
=============================================================================================================================================================================================
正在更新:
device-mapper-persistent-data x86_64 0.8.5-3.el7_9.2 updates 423 k
lvm2 x86_64 7:2.02.187-6.el7_9.3 updates 1.3 M
为依赖而更新:
device-mapper x86_64 7:1.02.170-6.el7_9.3 updates 297 k
device-mapper-event x86_64 7:1.02.170-6.el7_9.3 updates 192 k
device-mapper-event-libs x86_64 7:1.02.170-6.el7_9.3 updates 191 k
device-mapper-libs x86_64 7:1.02.170-6.el7_9.3 updates 325 k
lvm2-libs x86_64 7:2.02.187-6.el7_9.3 updates 1.1 M
事务概要
=============================================================================================================================================================================================
升级 2 软件包 (+5 依赖软件包)
总计:3.8 M
Downloading packages:
警告:/var/cache/yum/x86_64/7/updates/packages/lvm2-2.02.187-6.el7_9.3.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 检索密钥
导入 GPG key 0xF4A80EB5:
用户ID : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
指纹 : 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
软件包 : centos-release-7-9.2009.0.el7.centos.x86_64 (@anaconda)
来自 : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在更新 : 7:device-mapper-1.02.170-6.el7_9.3.x86_64 1/14
正在更新 : 7:device-mapper-libs-1.02.170-6.el7_9.3.x86_64 2/14
正在更新 : 7:device-mapper-event-libs-1.02.170-6.el7_9.3.x86_64 3/14
正在更新 : 7:device-mapper-event-1.02.170-6.el7_9.3.x86_64 4/14
正在更新 : 7:lvm2-libs-2.02.187-6.el7_9.3.x86_64 5/14
正在更新 : device-mapper-persistent-data-0.8.5-3.el7_9.2.x86_64 6/14
正在更新 : 7:lvm2-2.02.187-6.el7_9.3.x86_64 7/14
清理 : 7:lvm2-2.02.187-6.el7.x86_64 8/14
清理 : 7:lvm2-libs-2.02.187-6.el7.x86_64 9/14
清理 : 7:device-mapper-event-1.02.170-6.el7.x86_64 10/14
清理 : 7:device-mapper-event-libs-1.02.170-6.el7.x86_64 11/14
清理 : 7:device-mapper-1.02.170-6.el7.x86_64 12/14
清理 : 7:device-mapper-libs-1.02.170-6.el7.x86_64 13/14
清理 : device-mapper-persistent-data-0.8.5-3.el7.x86_64 14/14
验证中 : 7:lvm2-2.02.187-6.el7_9.3.x86_64 1/14
验证中 : device-mapper-persistent-data-0.8.5-3.el7_9.2.x86_64 2/14
验证中 : 7:device-mapper-event-1.02.170-6.el7_9.3.x86_64 3/14
验证中 : 7:device-mapper-libs-1.02.170-6.el7_9.3.x86_64 4/14
验证中 : 7:lvm2-libs-2.02.187-6.el7_9.3.x86_64 5/14
验证中 : 7:device-mapper-1.02.170-6.el7_9.3.x86_64 6/14
验证中 : 7:device-mapper-event-libs-1.02.170-6.el7_9.3.x86_64 7/14
验证中 : 7:device-mapper-event-libs-1.02.170-6.el7.x86_64 8/14
验证中 : 7:lvm2-libs-2.02.187-6.el7.x86_64 9/14
验证中 : 7:device-mapper-libs-1.02.170-6.el7.x86_64 10/14
验证中 : 7:lvm2-2.02.187-6.el7.x86_64 11/14
验证中 : device-mapper-persistent-data-0.8.5-3.el7.x86_64 12/14
验证中 : 7:device-mapper-event-1.02.170-6.el7.x86_64 13/14
验证中 : 7:device-mapper-1.02.170-6.el7.x86_64 14/14
更新完毕:
device-mapper-persistent-data.x86_64 0:0.8.5-3.el7_9.2 lvm2.x86_64 7:2.02.187-6.el7_9.3
作为依赖被升级:
device-mapper.x86_64 7:1.02.170-6.el7_9.3 device-mapper-event.x86_64 7:1.02.170-6.el7_9.3 device-mapper-event-libs.x86_64 7:1.02.170-6.el7_9.3
device-mapper-libs.x86_64 7:1.02.170-6.el7_9.3 lvm2-libs.x86_64 7:2.02.187-6.el7_9.3
完毕!
[root@localhost ~]#
3、设置stable镜像仓库
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@localhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
已加载插件:fastestmirror, langpacks
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
4、更新yum软件包索引
yum makecache fast
[root@localhost ~]# yum makecache fast
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.ustc.edu.cn
* updates: mirrors.ustc.edu.cn
base | 3.6 kB 00:00:00
docker-ce-stable | 3.5 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/2): docker-ce-stable/x86_64/updateinfo | 55 B 00:00:00
(2/2): docker-ce-stable/x86_64/primary_db | 51 kB 00:00:00
元数据缓存已建立
[root@localhost ~]#
5、安装docker 最新版本
yum -y install docker-ce
也可以安装指定版本
yum list docker-ce --showduplicates | sort -r
yum install -y docker-ce-18.09.8 docker-ce-cli-18.09.8 containerd.io
[root@localhost ~]# yum -y install docker-ce
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.ustc.edu.cn
* updates: mirrors.ustc.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 docker-ce.x86_64.3.20.10.1-3.el7 将被 安装
--> 正在处理依赖关系 container-selinux >= 2:2.74,它被软件包 3:docker-ce-20.10.1-3.el7.x86_64 需要
--> 正在处理依赖关系 containerd.io >= 1.4.1,它被软件包 3:docker-ce-20.10.1-3.el7.x86_64 需要
--> 正在处理依赖关系 docker-ce-cli,它被软件包 3:docker-ce-20.10.1-3.el7.x86_64 需要
--> 正在处理依赖关系 docker-ce-rootless-extras,它被软件包 3:docker-ce-20.10.1-3.el7.x86_64 需要
--> 正在检查事务
---> 软件包 container-selinux.noarch.2.2.119.2-1.911c772.el7_8 将被 安装
---> 软件包 containerd.io.x86_64.0.1.4.3-3.1.el7 将被 安装
---> 软件包 docker-ce-cli.x86_64.1.20.10.1-3.el7 将被 安装
---> 软件包 docker-ce-rootless-extras.x86_64.0.20.10.1-3.el7 将被 安装
--> 正在处理依赖关系 fuse-overlayfs >= 0.7,它被软件包 docker-ce-rootless-extras-20.10.1-3.el7.x86_64 需要
--> 正在处理依赖关系 slirp4netns >= 0.4,它被软件包 docker-ce-rootless-extras-20.10.1-3.el7.x86_64 需要
--> 正在检查事务
---> 软件包 fuse-overlayfs.x86_64.0.0.7.2-6.el7_8 将被 安装
--> 正在处理依赖关系 libfuse3.so.3(FUSE_3.2)(64bit),它被软件包 fuse-overlayfs-0.7.2-6.el7_8.x86_64 需要
--> 正在处理依赖关系 libfuse3.so.3(FUSE_3.0)(64bit),它被软件包 fuse-overlayfs-0.7.2-6.el7_8.x86_64 需要
--> 正在处理依赖关系 libfuse3.so.3()(64bit),它被软件包 fuse-overlayfs-0.7.2-6.el7_8.x86_64 需要
---> 软件包 slirp4netns.x86_64.0.0.4.3-4.el7_8 将被 安装
--> 正在检查事务
---> 软件包 fuse3-libs.x86_64.0.3.6.1-4.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
=============================================================================================================================================================================================
Package 架构 版本 源 大小
=============================================================================================================================================================================================
正在安装:
docker-ce x86_64 3:20.10.1-3.el7 docker-ce-stable 27 M
为依赖而安装:
container-selinux noarch 2:2.119.2-1.911c772.el7_8 extras 40 k
containerd.io x86_64 1.4.3-3.1.el7 docker-ce-stable 33 M
docker-ce-cli x86_64 1:20.10.1-3.el7 docker-ce-stable 33 M
docker-ce-rootless-extras x86_64 20.10.1-3.el7 docker-ce-stable 9.0 M
fuse-overlayfs x86_64 0.7.2-6.el7_8 extras 54 k
fuse3-libs x86_64 3.6.1-4.el7 extras 82 k
slirp4netns x86_64 0.4.3-4.el7_8 extras 81 k
事务概要
=============================================================================================================================================================================================
安装 1 软件包 (+7 依赖软件包)
总下载量:102 M
安装大小:423 M
Downloading packages:
(1/8): container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm | 40 kB 00:00:00
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-20.10.1-3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY ] 12 MB/s | 52 MB 00:00:04 ETA
docker-ce-20.10.1-3.el7.x86_64.rpm 的公钥尚未安装
(2/8): docker-ce-20.10.1-3.el7.x86_64.rpm | 27 MB 00:00:03
(3/8): containerd.io-1.4.3-3.1.el7.x86_64.rpm | 33 MB 00:00:03
(4/8): fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm | 54 kB 00:00:00
(5/8): fuse3-libs-3.6.1-4.el7.x86_64.rpm | 82 kB 00:00:00
(6/8): docker-ce-rootless-extras-20.10.1-3.el7.x86_64.rpm | 9.0 MB 00:00:00
(7/8): slirp4netns-0.4.3-4.el7_8.x86_64.rpm | 81 kB 00:00:00
(8/8): docker-ce-cli-20.10.1-3.el7.x86_64.rpm | 33 MB 00:00:02
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计 19 MB/s | 102 MB 00:00:05
从 https://mirrors.aliyun.com/docker-ce/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://mirrors.aliyun.com/docker-ce/linux/centos/gpg
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch 1/8
正在安装 : containerd.io-1.4.3-3.1.el7.x86_64 2/8
正在安装 : fuse3-libs-3.6.1-4.el7.x86_64 3/8
正在安装 : fuse-overlayfs-0.7.2-6.el7_8.x86_64 4/8
正在安装 : slirp4netns-0.4.3-4.el7_8.x86_64 5/8
正在安装 : 1:docker-ce-cli-20.10.1-3.el7.x86_64 6/8
正在安装 : docker-ce-rootless-extras-20.10.1-3.el7.x86_64 7/8
正在安装 : 3:docker-ce-20.10.1-3.el7.x86_64 8/8
验证中 : 1:docker-ce-cli-20.10.1-3.el7.x86_64 1/8
验证中 : fuse-overlayfs-0.7.2-6.el7_8.x86_64 2/8
验证中 : slirp4netns-0.4.3-4.el7_8.x86_64 3/8
验证中 : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch 4/8
验证中 : docker-ce-rootless-extras-20.10.1-3.el7.x86_64 5/8
验证中 : containerd.io-1.4.3-3.1.el7.x86_64 6/8
验证中 : fuse3-libs-3.6.1-4.el7.x86_64 7/8
验证中 : 3:docker-ce-20.10.1-3.el7.x86_64 8/8
已安装:
docker-ce.x86_64 3:20.10.1-3.el7
作为依赖被安装:
container-selinux.noarch 2:2.119.2-1.911c772.el7_8 containerd.io.x86_64 0:1.4.3-3.1.el7 docker-ce-cli.x86_64 1:20.10.1-3.el7 docker-ce-rootless-extras.x86_64 0:20.10.1-3.el7
fuse-overlayfs.x86_64 0:0.7.2-6.el7_8 fuse3-libs.x86_64 0:3.6.1-4.el7 slirp4netns.x86_64 0:0.4.3-4.el7_8
完毕!
6、启动docker
systemctl start docker
[root@localhost ~]# systemctl start docker
[root@localhost ~]#
7、查看
docker version
# 显示
Client:
Version: 18.09.8
API version: 1.39
Go version: go1.10.8
Git commit: 0dd43dd87f
Built: Wed Jul 17 17:40:31 2019
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.8
API version: 1.39 (minimum version 1.12)
Go version: go1.10.8
Git commit: 0dd43dd
Built: Wed Jul 17 17:10:42 2019
OS/Arch: linux/amd64
Experimental: false
[root@localhost ~]# docker version
Client: Docker Engine - Community
Version: 20.10.1
API version: 1.41
Go version: go1.13.15
Git commit: 831ebea
Built: Tue Dec 15 04:37:17 2020
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.1
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: f001486
Built: Tue Dec 15 04:35:42 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.3
GitCommit: 269548fa27e0089a8b8278fc4fc781d7f65a939b
runc:
Version: 1.0.0-rc92
GitCommit: ff819c7e9184c13b7c2607fe6c30ae19403a7aff
docker-init:
Version: 0.19.0
GitCommit: de40ad0
8、设置镜像源
vim /etc/docker/daemon.json
{
"registry-mirrors": ["http://hub-mirror.c.163.com"]
}
[root@localhost docker]# ll
总用量 8
-rw-r--r--. 1 root root 61 12月 27 22:44 daemon.json
-rw-------. 1 root root 244 12月 27 22:42 key.json
[root@localhost docker]# cat daemon.json
{
"registry-mirrors": ["http://hub-mirror.c.163.com"]
}
9、重启镜像源
systemctl restart docker
[root@localhost docker]# systemctl restart docker
[root@localhost docker]#