1、卸载旧版本
旧版本的 Docker 被称为docker或docker-engine。如果安装了这些,卸载它们以及相关的依赖项。
yum remove docker \docker-client \docker-client-latest \docker-common \docker-latest \docker-latest-logrotate \docker-logrotate \docker-engine
yum如果报告没有安装这些软件包,那也没关系。
/var/lib/docker/ 的内容,包括图像、容器、卷和网络,将被保留。 Docker 引擎包现在称为 docker-ce。
[root@localhost yum.repos.d]# yum remove docker \docker-client \docker-client-latest \docker-common \docker-latest \docker-latest-logrotate \docker-logrotate \docker-engine
Repository baseos is listed more than once in the configuration
Repository appstream is listed more than once in the configuration
No match for argument: docker
No match for argument: docker-client
No match for argument: docker-client-latest
No match for argument: docker-common
No match for argument: docker-latest
No match for argument: docker-latest-logrotate
No match for argument: docker-logrotate
No match for argument: docker-engine
No packages marked for removal.
Dependencies resolved.
Nothing to do.
Complete!
2、安装方法
您可以根据需要以不同的方式安装 Docker Engine:
-
大多数用户 设置 Docker 的存储库并从中安装,以简化安装和升级任务。这是推荐的方法。
-
一些用户下载 RPM 包并 手动安装并完全手动管理升级。这在诸如在无法访问 Internet 的气隙系统上安装 Docker 等情况下非常有用。
-
在测试和开发环境中,一些用户选择使用自动化 的便捷脚本来安装 Docker。
3、使用存储库安装
在新主机上首次安装 Docker Engine 之前,您需要设置 Docker 存储库。之后,您可以从存储库安装和更新 Docker。
3.1、设置存储库
安装yum-utils包(提供yum-config-manager 实用程序)并设置存储库。
yum install -y yum-utilsyum-config-manager \--add-repo \https://download.docker.com/linux/centos/docker-ce.repo
[root@localhost yum.repos.d]# yum install -y yum-utils
Repository baseos is listed more than once in the configuration
Repository appstream is listed more than once in the configuration
Last metadata expiration check: 0:03:44 ago on Wed 30 Nov 2022 09:18:40 AM CST.
Dependencies resolved.
============================================================================================================================================================================================================================== Package Architecture Version Repository Size
==============================================================================================================================================================================================================================Installing:yum-utils noarch 4.3.0-1.el9 baseos 41 k
Upgrading:dnf-plugins-core noarch 4.3.0-1.el9 baseos 35 kpython3-dnf-plugins-core noarch 4.3.0-1.el9 baseos 245 kTransaction Summary
==============================================================================================================================================================================================================================Install 1 Package
Upgrade 2 PackagesTotal download size: 321 k
Downloading Packages:
[MIRROR] dnf-plugins-core-4.3.0-1.el9.noarch.rpm: Curl error (60): SSL peer certificate or SSH remote key was not OK for https://cp-ap.int.vertivco.com:6082/php/uid.php?vsys=1&rule=4&token=4fKKRW38ZnNn7PqvAWD5PAU1IDU=&url=http://ftp.riken.jp%2fLinux%2fcentos-stream%2f9-stream%2fBaseOS%2fx86_64%2fos%2fPackages%2fdnf-plugins-core-4.3.0-1.el9.noarch.rpm [SSL certificate problem: self-signed certificate in certificate chain]
[MIRROR] python3-dnf-plugins-core-4.3.0-1.el9.noarch.rpm: Curl error (60): SSL peer certificate or SSH remote key was not OK for https://cp-ap.int.vertivco.com:6082/php/uid.php?vsys=1&rule=4&token=OE0rJW__iaPAd0bJodVE856tPPg=&url=http://ftp.riken.jp%2fLinux%2fcentos-stream%2f9-stream%2fBaseOS%2fx86_64%2fos%2fPackages%2fpython3-dnf-plugins-core-4.3.0-1.el9.noarch.rpm [SSL certificate problem: self-signed certificate in certificate chain]
[MIRROR] yum-utils-4.3.0-1.el9.noarch.rpm: Curl error (60): SSL peer certificate or SSH remote key was not OK for https://cp-ap.int.vertivco.com:6082/php/uid.php?vsys=1&rule=4&token=AQUZEpJ04yeybBoietnuRrhaH_g=&url=http://ftp.riken.jp%2fLinux%2fcentos-stream%2f9-stream%2fBaseOS%2fx86_64%2fos%2fPackages%2fyum-utils-4.3.0-1.el9.noarch.rpm [SSL certificate problem: self-signed certificate in certificate chain]
(1/3): dnf-plugins-core-4.3.0-1.el9.noarch.rpm 36 kB/s | 35 kB 00:00
(2/3): yum-utils-4.3.0-1.el9.noarch.rpm 39 kB/s | 41 kB 00:01
(3/3): python3-dnf-plugins-core-4.3.0-1.el9.noarch.rpm 215 kB/s | 245 kB 00:01
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Total 135 kB/s | 321 kB 00:02
CentOS Stream 9 - BaseOS 1.6 MB/s | 1.6 kB 00:00
Importing GPG key 0x8483C65D:Userid : "CentOS (CentOS Official Signing Key) <security@centos.org>"Fingerprint: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65DFrom : /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transactionPreparing : 1/1 Upgrading : python3-dnf-plugins-core-4.3.0-1.el9.noarch 1/5 Upgrading : dnf-plugins-core-4.3.0-1.el9.noarch 2/5 Installing : yum-utils-4.3.0-1.el9.noarch 3/5 Cleanup : dnf-plugins-core-4.1.0-3.el9.noarch 4/5 Cleanup : python3-dnf-plugins-core-4.1.0-3.el9.noarch 5/5 Running scriptlet: python3-dnf-plugins-core-4.1.0-3.el9.noarch 5/5 Verifying : yum-utils-4.3.0-1.el9.noarch 1/5 Verifying : dnf-plugins-core-4.3.0-1.el9.noarch 2/5 Verifying : dnf-plugins-core-4.1.0-3.el9.noarch 3/5 Verifying : python3-dnf-plugins-core-4.3.0-1.el9.noarch 4/5 Verifying : python3-dnf-plugins-core-4.1.0-3.el9.noarch 5/5 Upgraded:dnf-plugins-core-4.3.0-1.el9.noarch python3-dnf-plugins-core-4.3.0-1.el9.noarch
Installed:yum-utils-4.3.0-1.el9.noarch Complete!
[root@localhost yum.repos.d]# yum-config-manager \--add-repo \https://download.docker.com/linux/centos/docker-ce.repo
Repository baseos is listed more than once in the configuration
Repository appstream is listed more than once in the configuration
Adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
3.2、安装 Docker 引擎
3.2.1、安装最新版本的 Docker Engine、containerd 和 Docker Compose
安装最新版本的 Docker Engine、containerd 和 Docker Compose 或转到下一步安装特定版本:
yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
如果提示接受 GPG 密钥,请验证指纹是否匹配 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35,如果匹配,则接受。
此命令安装 Docker,但不会启动 Docker。它还会创建一个 docker组,但是默认情况下不会向该组添加任何用户。
[root@localhost yum.repos.d]# yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
Repository baseos is listed more than once in the configuration
Repository appstream is listed more than once in the configuration
Docker CE Stable - x86_64 5.4 kB/s | 12 kB 00:02
Dependencies resolved.
============================================================================================================================================================================================================================== Package Architecture Version Repository Size
==============================================================================================================================================================================================================================Installing:containerd.io x86_64 1.6.10-3.1.el9 docker-ce-stable 32 Mreplacing runc.x86_64 4:1.1.4-1.el9docker-ce x86_64 3:20.10.21-3.el9 docker-ce-stable 21 Mdocker-ce-cli x86_64 1:20.10.21-3.el9 docker-ce-stable 29 Mdocker-compose-plugin x86_64 2.12.2-3.el9 docker-ce-stable 10 M
Upgrading:buildah x86_64 1:1.28.0-2.el9 appstream 8.0 M
Installing dependencies:docker-ce-rootless-extras x86_64 20.10.21-3.el9 docker-ce-stable 3.7 M
Installing weak dependencies:docker-scan-plugin x86_64 0.21.0-3.el9 docker-ce-stable 3.8 MTransaction Summary
==============================================================================================================================================================================================================================Install 6 Packages
Upgrade 1 PackageTotal download size: 107 M
Is this ok [y/N]: y
Downloading Packages:
(1/7): docker-ce-cli-20.10.21-3.el9.x86_64.rpm 4.8 MB/s | 29 MB 00:06
(2/7): docker-ce-rootless-extras-20.10.21-3.el9.x86_64.rpm 916 kB/s | 3.7 MB 00:04
(3/7): containerd.io-1.6.10-3.1.el9.x86_64.rpm 3.1 MB/s | 32 MB 00:10
(4/7): docker-ce-20.10.21-3.el9.x86_64.rpm 1.7 MB/s | 21 MB 00:12
[MIRROR] buildah-1.28.0-2.el9.x86_64.rpm: Curl error (60): SSL peer certificate or SSH remote key was not OK for https://cp-ap.int.vertivco.com:6082/php/uid.php?vsys=1&rule=4&token=SA_hcQTX7zgekXQRMEHfgfMBZ6E=&url=http://ftp.yz.yamagata-u.ac.jp%2fpub%2flinux%2fcentos-stream%2f9-stream%2fAppStream%2fx86_64%2fos%2fPackages%2fbuildah-1.28.0-2.el9.x86_64.rpm [SSL certificate problem: self-signed certificate in certificate chain]
(5/7): docker-compose-plugin-2.12.2-3.el9.x86_64.rpm 2.5 MB/s | 10 MB 00:04
(6/7): buildah-1.28.0-2.el9.x86_64.rpm 3.1 MB/s | 8.0 MB 00:02
(7/7): docker-scan-plugin-0.21.0-3.el9.x86_64.rpm 792 kB/s | 3.8 MB 00:04
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Total 6.5 MB/s | 107 MB 00:16
Docker CE Stable - x86_64 1.5 kB/s | 1.6 kB 00:01
Importing GPG key 0x621E9F35:Userid : "Docker Release (CE rpm) <docker@docker.com>"Fingerprint: 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35From : https://download.docker.com/linux/centos/gpg
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transactionPreparing : 1/1 Installing : docker-scan-plugin-0.21.0-3.el9.x86_64 1/9 Running scriptlet: docker-scan-plugin-0.21.0-3.el9.x86_64 1/9 Installing : docker-ce-cli-1:20.10.21-3.el9.x86_64 2/9 Running scriptlet: docker-ce-cli-1:20.10.21-3.el9.x86_64 2/9 Installing : containerd.io-1.6.10-3.1.el9.x86_64 3/9 Running scriptlet: containerd.io-1.6.10-3.1.el9.x86_64 3/9 Installing : docker-ce-rootless-extras-20.10.21-3.el9.x86_64 4/9 Running scriptlet: docker-ce-rootless-extras-20.10.21-3.el9.x86_64 4/9 Installing : docker-ce-3:20.10.21-3.el9.x86_64 5/9 Running scriptlet: docker-ce-3:20.10.21-3.el9.x86_64 5/9 Upgrading : buildah-1:1.28.0-2.el9.x86_64 6/9 Installing : docker-compose-plugin-2.12.2-3.el9.x86_64 7/9 Running scriptlet: docker-compose-plugin-2.12.2-3.el9.x86_64 7/9 Cleanup : buildah-1:1.27.0-2.el9.x86_64 8/9 Obsoleting : runc-4:1.1.4-1.el9.x86_64 9/9 Running scriptlet: runc-4:1.1.4-1.el9.x86_64 9/9 Verifying : containerd.io-1.6.10-3.1.el9.x86_64 1/9 Verifying : runc-4:1.1.4-1.el9.x86_64 2/9 Verifying : docker-ce-3:20.10.21-3.el9.x86_64 3/9 Verifying : docker-ce-cli-1:20.10.21-3.el9.x86_64 4/9 Verifying : docker-ce-rootless-extras-20.10.21-3.el9.x86_64 5/9 Verifying : docker-compose-plugin-2.12.2-3.el9.x86_64 6/9 Verifying : docker-scan-plugin-0.21.0-3.el9.x86_64 7/9 Verifying : buildah-1:1.28.0-2.el9.x86_64 8/9 Verifying : buildah-1:1.27.0-2.el9.x86_64 9/9 Upgraded:buildah-1:1.28.0-2.el9.x86_64
Installed:containerd.io-1.6.10-3.1.el9.x86_64 docker-ce-3:20.10.21-3.el9.x86_64 docker-ce-cli-1:20.10.21-3.el9.x86_64 docker-ce-rootless-extras-20.10.21-3.el9.x86_64 docker-compose-plugin-2.12.2-3.el9.x86_64 docker-scan-plugin-0.21.0-3.el9.x86_64 Complete!
3.2.2、安装特定版本的 Docker 引擎
要安装特定版本的 Docker 引擎,请在存储库中列出可用版本,然后选择并安装:
列出并排序存储库中可用的版本。 此示例按版本号从高到低对结果进行排序,并被截断:
yum list docker-ce --showduplicates | sort -r
[root@localhost yum.repos.d]# yum list docker-ce --showduplicates | sort -r
Repository baseos is listed more than once in the configuration
Repository appstream is listed more than once in the configuration
Last metadata expiration check: 0:03:30 ago on Wed 30 Nov 2022 09:23:31 AM CST.
Installed Packages
docker-ce.x86_64 3:20.10.21-3.el9 docker-ce-stable
docker-ce.x86_64 3:20.10.21-3.el9 @docker-ce-stable
docker-ce.x86_64 3:20.10.20-3.el9 docker-ce-stable
docker-ce.x86_64 3:20.10.19-3.el9 docker-ce-stable
docker-ce.x86_64 3:20.10.18-3.el9 docker-ce-stable
docker-ce.x86_64 3:20.10.17-3.el9 docker-ce-stable
docker-ce.x86_64 3:20.10.16-3.el9 docker-ce-stable
docker-ce.x86_64 3:20.10.15-3.el9 docker-ce-stable
Available Packages
返回的列表取决于启用了哪些存储库,并且特定于您的 CentOS 版本。
3.2.3、安装特定版本
通过其完全限定的包名称安装特定版本,即包名称 ( docker-ce) 加上版本字符串(第 2 列),从第一个冒号 (:) 开始,直到第一个连字符,由连字符 ( - ) 分隔。例如,docker-ce-20.10.15。
yum install docker-ce-20.10.15 docker-ce-cli-20.10.15 containerd.io docker-compose-plugin
此命令安装 Docker,但不会启动 Docker。它还会创建一个 docker组,但是默认情况下不会向该组添加任何用户。
[root@localhost yum.repos.d]# yum install docker-ce-20.10.15 docker-ce-cli-20.10.15 containerd.io docker-compose-plugin
Repository baseos is listed more than once in the configuration
Repository appstream is listed more than once in the configuration
Last metadata expiration check: 0:06:52 ago on Wed 30 Nov 2022 09:23:31 AM CST.
Package containerd.io-1.6.10-3.1.el9.x86_64 is already installed.
Package docker-compose-plugin-2.12.2-3.el9.x86_64 is already installed.
Dependencies resolved.
============================================================================================================================================================================================================================== Package Architecture Version Repository Size
==============================================================================================================================================================================================================================Downgrading:docker-ce x86_64 3:20.10.15-3.el9 docker-ce-stable 21 Mdocker-ce-cli x86_64 1:20.10.15-3.el9 docker-ce-stable 29 MTransaction Summary
==============================================================================================================================================================================================================================Downgrade 2 PackagesTotal download size: 50 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): docker-ce-20.10.15-3.el9.x86_64.rpm 5.0 MB/s | 21 MB 00:04
(2/2): docker-ce-cli-20.10.15-3.el9.x86_64.rpm 2.9 MB/s | 29 MB 00:10
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Total 5.0 MB/s | 50 MB 00:10
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transactionPreparing : 1/1 Downgrading : docker-ce-cli-1:20.10.15-3.el9.x86_64 1/4 Running scriptlet: docker-ce-cli-1:20.10.15-3.el9.x86_64 1/4 Downgrading : docker-ce-3:20.10.15-3.el9.x86_64 2/4 Running scriptlet: docker-ce-3:20.10.15-3.el9.x86_64 2/4 Running scriptlet: docker-ce-3:20.10.21-3.el9.x86_64 3/4 Cleanup : docker-ce-3:20.10.21-3.el9.x86_64 3/4 Running scriptlet: docker-ce-3:20.10.21-3.el9.x86_64 3/4 Cleanup : docker-ce-cli-1:20.10.21-3.el9.x86_64 4/4 Running scriptlet: docker-ce-cli-1:20.10.21-3.el9.x86_64 4/4 Verifying : docker-ce-3:20.10.15-3.el9.x86_64 1/4 Verifying : docker-ce-3:20.10.21-3.el9.x86_64 2/4 Verifying : docker-ce-cli-1:20.10.15-3.el9.x86_64 3/4 Verifying : docker-ce-cli-1:20.10.21-3.el9.x86_64 4/4 Downgraded:docker-ce-3:20.10.15-3.el9.x86_64 docker-ce-cli-1:20.10.15-3.el9.x86_64 Complete!
4、 启动docker,检查版本
systemctl start docker.service
systemctl enable docker.service #设置docker自启动
[root@localhost yum.repos.d]# docker --version
Docker version 20.10.15, build fd82621
[root@localhost yum.repos.d]# systemctl start docker
[root@localhost yum.repos.d]# systemctl status docker
● docker.service - Docker Application Container EngineLoaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)Active: active (running) since Wed 2022-11-30 09:30:59 CST; 7s ago
TriggeredBy: ● docker.socketDocs: https://docs.docker.comMain PID: 34714 (dockerd)Tasks: 8Memory: 34.8MCPU: 330msCGroup: /system.slice/docker.service└─34714 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sockNov 30 09:30:58 localhost.localdomain dockerd[34714]: time="2022-11-30T09:30:58.954299837+08:00" level=info msg="ccResolverWrapper: sending update to cc: {[{unix:///run/containerd/containerd.sock <nil> 0 <nil>}] <nil> <n>Nov 30 09:30:58 localhost.localdomain dockerd[34714]: time="2022-11-30T09:30:58.954358327+08:00" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc
Nov 30 09:30:58 localhost.localdomain dockerd[34714]: time="2022-11-30T09:30:58.955519393+08:00" level=error msg="Failed to built-in GetDriver graph btrfs /var/lib/docker"
Nov 30 09:30:58 localhost.localdomain dockerd[34714]: time="2022-11-30T09:30:58.976334470+08:00" level=info msg="Loading containers: start."
Nov 30 09:30:59 localhost.localdomain dockerd[34714]: time="2022-11-30T09:30:59.267098060+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to se>Nov 30 09:30:59 localhost.localdomain dockerd[34714]: time="2022-11-30T09:30:59.392567556+08:00" level=info msg="Loading containers: done."
Nov 30 09:30:59 localhost.localdomain dockerd[34714]: time="2022-11-30T09:30:59.412951714+08:00" level=info msg="Docker daemon" commit=4433bf6 graphdriver(s)=overlay2 version=20.10.15
Nov 30 09:30:59 localhost.localdomain dockerd[34714]: time="2022-11-30T09:30:59.413842208+08:00" level=info msg="Daemon has completed initialization"
Nov 30 09:30:59 localhost.localdomain systemd[1]: Started Docker Application Container Engine.
Nov 30 09:30:59 localhost.localdomain dockerd[34714]: time="2022-11-30T09:30:59.446355043+08:00" level=info msg="API listen on /run/docker.sock"
[root@localhost /]# systemctl enable docker.service
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.