【Docker】安装及部署

一、Ubuntu使用apt安装Docker

官方安装文档:https://docs.docker.com/engine/install/ubuntu/

1、准备安装环境

[root@Docker-Ubu1804-p11:~]# apt update 
[root@Docker-Ubu1804-p11:~]# apt install ca-certificates curl gnupg -y

2、添加Docker相关 GPG 证书配置

[root@Docker-Ubu1804-p11:~]# install -m 0755 -d /etc/apt/keyrings
[root@Docker-Ubu1804-p11:~]# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
[root@Docker-Ubu1804-p11:~]# chmod a+r /etc/apt/keyrings/docker.gpg

3、添加相关Docker安装源

[root@Docker-Ubu1804-p11:~]# echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null

 

4、更新源缓存,列出可安装的docker版本

复制代码
[root@Docker-Ubu1804-p11:~]# apt update
Get:1 https://download.docker.com/linux/ubuntu bionic InRelease [64.4 kB]    
Hit:2 http://cn.archive.ubuntu.com/ubuntu bionic InRelease                   
Get:3 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages [36.0 kB]
Hit:4 http://cn.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:5 http://cn.archive.ubuntu.com/ubuntu bionic-backports InRelease
Hit:6 http://cn.archive.ubuntu.com/ubuntu bionic-security InRelease
Fetched 100 kB in 2s (58.8 kB/s)
Reading package lists... Done
Building dependency tree       
Reading state information... Done
110 packages can be upgraded. Run 'apt list --upgradable' to see them.

[root@Docker
-Ubu1804-p11:~]# apt-cache madison docker-ce | awk '{ print $3 }' 5:23.0.4-1~ubuntu.18.04~bionic 5:23.0.3-1~ubuntu.18.04~bionic 5:23.0.2-1~ubuntu.18.04~bionic 5:23.0.1-1~ubuntu.18.04~bionic 5:23.0.0-1~ubuntu.18.04~bionic 5:20.10.24~3-0~ubuntu-bionic 5:20.10.23~3-0~ubuntu-bionic 5:20.10.22~3-0~ubuntu-bionic 5:20.10.21~3-0~ubuntu-bionic 5:20.10.20~3-0~ubuntu-bionic 5:20.10.19~3-0~ubuntu-bionic 5:20.10.18~3-0~ubuntu-bionic 5:20.10.17~3-0~ubuntu-bionic 5:20.10.16~3-0~ubuntu-bionic 5:20.10.15~3-0~ubuntu-bionic 5:20.10.14~3-0~ubuntu-bionic 5:20.10.13~3-0~ubuntu-bionic 5:20.10.12~3-0~ubuntu-bionic 5:20.10.11~3-0~ubuntu-bionic 5:20.10.10~3-0~ubuntu-bionic 5:20.10.9~3-0~ubuntu-bionic 5:20.10.8~3-0~ubuntu-bionic 5:20.10.7~3-0~ubuntu-bionic 5:20.10.6~3-0~ubuntu-bionic 5:20.10.5~3-0~ubuntu-bionic 5:20.10.4~3-0~ubuntu-bionic 5:20.10.3~3-0~ubuntu-bionic 5:20.10.2~3-0~ubuntu-bionic 5:20.10.1~3-0~ubuntu-bionic 5:20.10.0~3-0~ubuntu-bionic 5:19.03.15~3-0~ubuntu-bionic 5:19.03.14~3-0~ubuntu-bionic 5:19.03.13~3-0~ubuntu-bionic 5:19.03.12~3-0~ubuntu-bionic 5:19.03.11~3-0~ubuntu-bionic 5:19.03.10~3-0~ubuntu-bionic 5:19.03.9~3-0~ubuntu-bionic 5:19.03.8~3-0~ubuntu-bionic 5:19.03.7~3-0~ubuntu-bionic 5:19.03.6~3-0~ubuntu-bionic 5:19.03.5~3-0~ubuntu-bionic 5:19.03.4~3-0~ubuntu-bionic 5:19.03.3~3-0~ubuntu-bionic 5:19.03.2~3-0~ubuntu-bionic 5:19.03.1~3-0~ubuntu-bionic 5:19.03.0~3-0~ubuntu-bionic 5:18.09.9~3-0~ubuntu-bionic 5:18.09.8~3-0~ubuntu-bionic 5:18.09.7~3-0~ubuntu-bionic 5:18.09.6~3-0~ubuntu-bionic 5:18.09.5~3-0~ubuntu-bionic 5:18.09.4~3-0~ubuntu-bionic 5:18.09.3~3-0~ubuntu-bionic 5:18.09.2~3-0~ubuntu-bionic 5:18.09.1~3-0~ubuntu-bionic 5:18.09.0~3-0~ubuntu-bionic 18.06.3~ce~3-0~ubuntu 18.06.2~ce~3-0~ubuntu 18.06.1~ce~3-0~ubuntu 18.06.0~ce~3-0~ubuntu 18.03.1~ce~3-0~ubuntu
复制代码

5、指定版本选择安装Docker

 Docker版本的选择通常需要配合 Kubernetes 版本兼容性

复制代码
[root@Docker-Ubu1804-p11:~]# apt install docker-ce=5:19.03.15~3-0~ubuntu-bionic docker-ce-cli=5:19.03.15~3-0~ubuntu-bionic -y
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  aufs-tools cgroupfs-mount containerd.io libltdl7 pigz
The following NEW packages will be installed:
  aufs-tools cgroupfs-mount containerd.io docker-ce docker-ce-cli libltdl7 pigz
0 upgraded, 7 newly installed, 0 to remove and 110 not upgraded.
Need to get 95.5 MB of archives.
After this operation, 414 MB of additional disk space will be used.
Get:1 https://download.docker.com/linux/ubuntu bionic/stable amd64 containerd.io amd64 1.6.20-1 [28.3 MB]
Get:2 http://cn.archive.ubuntu.com/ubuntu bionic/universe amd64 pigz amd64 2.4-1 [57.4 kB]
Get:3 http://cn.archive.ubuntu.com/ubuntu bionic/universe amd64 aufs-tools amd64 1:4.9+20170918-1ubuntu1 [104 kB]
Get:4 https://download.docker.com/linux/ubuntu bionic/stable amd64 docker-ce-cli amd64 5:19.03.15~3-0~ubuntu-bionic [44.2 MB]
Get:5 http://cn.archive.ubuntu.com/ubuntu bionic/universe amd64 cgroupfs-mount all 1.4 [6320 B]
Get:6 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libltdl7 amd64 2.4.6-2 [38.8 kB]
Get:7 https://download.docker.com/linux/ubuntu bionic/stable amd64 docker-ce amd64 5:19.03.15~3-0~ubuntu-bionic [22.8 MB]
Fetched 95.5 MB in 7s (13.8 MB/s)                                                                                                              
Selecting previously unselected package pigz.
(Reading database ... 108264 files and directories currently installed.)
Preparing to unpack .../0-pigz_2.4-1_amd64.deb ...
Unpacking pigz (2.4-1) ...
Selecting previously unselected package aufs-tools.
Preparing to unpack .../1-aufs-tools_1%3a4.9+20170918-1ubuntu1_amd64.deb ...
Unpacking aufs-tools (1:4.9+20170918-1ubuntu1) ...
Selecting previously unselected package cgroupfs-mount.
Preparing to unpack .../2-cgroupfs-mount_1.4_all.deb ...
Unpacking cgroupfs-mount (1.4) ...
Selecting previously unselected package containerd.io.
Preparing to unpack .../3-containerd.io_1.6.20-1_amd64.deb ...
Unpacking containerd.io (1.6.20-1) ...
Selecting previously unselected package docker-ce-cli.
Preparing to unpack .../4-docker-ce-cli_5%3a19.03.15~3-0~ubuntu-bionic_amd64.deb ...
Unpacking docker-ce-cli (5:19.03.15~3-0~ubuntu-bionic) ...
Selecting previously unselected package docker-ce.
Preparing to unpack .../5-docker-ce_5%3a19.03.15~3-0~ubuntu-bionic_amd64.deb ...
Unpacking docker-ce (5:19.03.15~3-0~ubuntu-bionic) ...
Selecting previously unselected package libltdl7:amd64.
Preparing to unpack .../6-libltdl7_2.4.6-2_amd64.deb ...
Unpacking libltdl7:amd64 (2.4.6-2) ...
Setting up aufs-tools (1:4.9+20170918-1ubuntu1) ...
Setting up containerd.io (1.6.20-1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /lib/systemd/system/containerd.service.
Setting up cgroupfs-mount (1.4) ...
Setting up libltdl7:amd64 (2.4.6-2) ...
Setting up docker-ce-cli (5:19.03.15~3-0~ubuntu-bionic) ...
Setting up pigz (2.4-1) ...
Setting up docker-ce (5:19.03.15~3-0~ubuntu-bionic) ...
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service.
Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker.socket.
Processing triggers for libc-bin (2.27-3ubuntu1.5) ...
Processing triggers for systemd (237-3ubuntu10.50) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for ureadahead (0.100.0-21) ...
[root@Docker-Ubu1804-p11:~]# 
复制代码

 

6、 查看Docker版本信息

复制代码
[root@Docker-Ubu1804-p11:~]# docker version
Client: Docker Engine - Community
 Version:           19.03.15
 API version:       1.40
 Go version:        go1.13.15
 Git commit:        99e3ed8919
 Built:             Sat Jan 30 03:16:51 2021
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.15
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       99e3ed8919
  Built:            Sat Jan 30 03:15:20 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.20
  GitCommit:        2806fc1057397dbaeefbea0e4e17bddfbd388f38
 runc:
  Version:          1.1.5
  GitCommit:        v1.1.5-0-gf19387a
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683
[root@Docker-Ubu1804-p11:~]# 
复制代码

 

7、设置镜像加速

阿里云镜像加速:https://help.aliyun.com/document_detail/60750.html?spm=5176.21213303.J_6704733920.27.5e6d53c9COxst4&scm=20140722.S_help@@%E6%96%87%E6%A1%A3@@60750._.ID_help@@%E6%96%87%E6%A1%A3@@60750-RL_%E9%95%9C%E5%83%8F%E5%8A%A0%E9%80%9F-LOC_main-OR_ser-V_2-RK_rerank-P0_3

sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["镜像加速地址"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

 

 

二、CentOS7 yum安装Docker

基于阿里云源安装文档:https://developer.aliyun.com/mirror/docker-ce?spm=a2c6h.13651102.0.0.3e221b11sUMKNV

1、安装基础依赖工具

复制代码
[root@Template-CentOS7-7 ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 device-mapper-persistent-data.x86_64.0.0.7.3-3.el7 将被 升级
---> 软件包 device-mapper-persistent-data.x86_64.0.0.8.5-3.el7_9.2 将被 更新
---> 软件包 lvm2.x86_64.7.2.02.177-4.el7 将被 升级
---> 软件包 lvm2.x86_64.7.2.02.187-6.el7_9.5 将被 更新
--> 正在处理依赖关系 lvm2-libs = 7:2.02.187-6.el7_9.5,它被软件包 7:lvm2-2.02.187-6.el7_9.5.x86_64 需要
---> 软件包 yum-utils.noarch.0.1.1.31-54.el7_8 将被 安装
--> 正在处理依赖关系 python-kitchen,它被软件包 yum-utils-1.1.31-54.el7_8.noarch 需要
--> 正在处理依赖关系 libxml2-python,它被软件包 yum-utils-1.1.31-54.el7_8.noarch 需要
--> 正在检查事务
---> 软件包 libxml2-python.x86_64.0.2.9.1-6.el7_9.6 将被 安装
--> 正在处理依赖关系 libxml2 = 2.9.1-6.el7_9.6,它被软件包 libxml2-python-2.9.1-6.el7_9.6.x86_64 需要
---> 软件包 lvm2-libs.x86_64.7.2.02.177-4.el7 将被 升级
---> 软件包 lvm2-libs.x86_64.7.2.02.187-6.el7_9.5 将被 更新
--> 正在处理依赖关系 device-mapper-event = 7:1.02.170-6.el7_9.5,它被软件包 7:lvm2-libs-2.02.187-6.el7_9.5.x86_64 需要
---> 软件包 python-kitchen.noarch.0.1.1.1-5.el7 将被 安装
--> 正在处理依赖关系 python-chardet,它被软件包 python-kitchen-1.1.1-5.el7.noarch 需要
--> 正在检查事务
---> 软件包 device-mapper-event.x86_64.7.1.02.146-4.el7 将被 升级
---> 软件包 device-mapper-event.x86_64.7.1.02.170-6.el7_9.5 将被 更新
--> 正在处理依赖关系 device-mapper-event-libs = 7:1.02.170-6.el7_9.5,它被软件包 7:device-mapper-event-1.02.170-6.el7_9.5.x86_64 需要
--> 正在处理依赖关系 device-mapper = 7:1.02.170-6.el7_9.5,它被软件包 7:device-mapper-event-1.02.170-6.el7_9.5.x86_64 需要
---> 软件包 libxml2.x86_64.0.2.9.1-6.el7_2.3 将被 升级
---> 软件包 libxml2.x86_64.0.2.9.1-6.el7_9.6 将被 更新
---> 软件包 python-chardet.noarch.0.2.2.1-3.el7 将被 安装
--> 正在检查事务
---> 软件包 device-mapper.x86_64.7.1.02.146-4.el7 将被 升级
--> 正在处理依赖关系 device-mapper = 7:1.02.146-4.el7,它被软件包 7:device-mapper-libs-1.02.146-4.el7.x86_64 需要
---> 软件包 device-mapper.x86_64.7.1.02.170-6.el7_9.5 将被 更新
---> 软件包 device-mapper-event-libs.x86_64.7.1.02.146-4.el7 将被 升级
---> 软件包 device-mapper-event-libs.x86_64.7.1.02.170-6.el7_9.5 将被 更新
--> 正在检查事务
---> 软件包 device-mapper-libs.x86_64.7.1.02.146-4.el7 将被 升级
---> 软件包 device-mapper-libs.x86_64.7.1.02.170-6.el7_9.5 将被 更新
--> 解决依赖关系完成

依赖关系解决

================================================================================================================================================
 Package                                        架构                    版本                                     源                        大小
================================================================================================================================================
正在安装:
 yum-utils                                      noarch                  1.1.31-54.el7_8                          base                     122 k
正在更新:
 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.5                     updates                  1.3 M
为依赖而安装:
 libxml2-python                                 x86_64                  2.9.1-6.el7_9.6                          updates                  247 k
 python-chardet                                 noarch                  2.2.1-3.el7                              base                     227 k
 python-kitchen                                 noarch                  1.1.1-5.el7                              base                     267 k
为依赖而更新:
 device-mapper                                  x86_64                  7:1.02.170-6.el7_9.5                     updates                  297 k
 device-mapper-event                            x86_64                  7:1.02.170-6.el7_9.5                     updates                  192 k
 device-mapper-event-libs                       x86_64                  7:1.02.170-6.el7_9.5                     updates                  192 k
 device-mapper-libs                             x86_64                  7:1.02.170-6.el7_9.5                     updates                  325 k
 libxml2                                        x86_64                  2.9.1-6.el7_9.6                          updates                  668 k
 lvm2-libs                                      x86_64                  7:2.02.187-6.el7_9.5                     updates                  1.1 M

事务概要
================================================================================================================================================
安装  1 软件包 (+3 依赖软件包)
升级  2 软件包 (+6 依赖软件包)

总下载量:5.3 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/12): device-mapper-event-1.02.170-6.el7_9.5.x86_64.rpm                                                                | 192 kB  00:00:00     
(2/12): device-mapper-1.02.170-6.el7_9.5.x86_64.rpm                                                                      | 297 kB  00:00:00     
(3/12): device-mapper-event-libs-1.02.170-6.el7_9.5.x86_64.rpm                                                           | 192 kB  00:00:00     
(4/12): device-mapper-libs-1.02.170-6.el7_9.5.x86_64.rpm                                                                 | 325 kB  00:00:00     
(5/12): device-mapper-persistent-data-0.8.5-3.el7_9.2.x86_64.rpm                                                         | 423 kB  00:00:00     
(6/12): libxml2-python-2.9.1-6.el7_9.6.x86_64.rpm                                                                        | 247 kB  00:00:00     
(7/12): libxml2-2.9.1-6.el7_9.6.x86_64.rpm                                                                               | 668 kB  00:00:00     
(8/12): lvm2-libs-2.02.187-6.el7_9.5.x86_64.rpm                                                                          | 1.1 MB  00:00:00     
(9/12): lvm2-2.02.187-6.el7_9.5.x86_64.rpm                                                                               | 1.3 MB  00:00:00     
(10/12): python-chardet-2.2.1-3.el7.noarch.rpm                                                                           | 227 kB  00:00:00     
(11/12): python-kitchen-1.1.1-5.el7.noarch.rpm                                                                           | 267 kB  00:00:00     
(12/12): yum-utils-1.1.31-54.el7_8.noarch.rpm                                                                            | 122 kB  00:00:00     
------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                            4.2 MB/s | 5.3 MB  00:00:01     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在更新    : 7:device-mapper-libs-1.02.170-6.el7_9.5.x86_64                                                                             1/20 
  正在更新    : 7:device-mapper-1.02.170-6.el7_9.5.x86_64                                                                                  2/20 
  正在更新    : 7:device-mapper-event-libs-1.02.170-6.el7_9.5.x86_64                                                                       3/20 
  正在更新    : 7:device-mapper-event-1.02.170-6.el7_9.5.x86_64                                                                            4/20 
  正在更新    : 7:lvm2-libs-2.02.187-6.el7_9.5.x86_64                                                                                      5/20 
  正在更新    : device-mapper-persistent-data-0.8.5-3.el7_9.2.x86_64                                                                       6/20 
  正在更新    : libxml2-2.9.1-6.el7_9.6.x86_64                                                                                             7/20 
  正在安装    : libxml2-python-2.9.1-6.el7_9.6.x86_64                                                                                      8/20 
  正在安装    : python-chardet-2.2.1-3.el7.noarch                                                                                          9/20 
  正在安装    : python-kitchen-1.1.1-5.el7.noarch                                                                                         10/20 
  正在安装    : yum-utils-1.1.31-54.el7_8.noarch                                                                                          11/20 
  正在更新    : 7:lvm2-2.02.187-6.el7_9.5.x86_64                                                                                          12/20 
  清理        : 7:lvm2-2.02.177-4.el7.x86_64                                                                                              13/20 
  清理        : 7:lvm2-libs-2.02.177-4.el7.x86_64                                                                                         14/20 
  清理        : 7:device-mapper-event-1.02.146-4.el7.x86_64                                                                               15/20 
  清理        : 7:device-mapper-event-libs-1.02.146-4.el7.x86_64                                                                          16/20 
  清理        : 7:device-mapper-1.02.146-4.el7.x86_64                                                                                     17/20 
  清理        : 7:device-mapper-libs-1.02.146-4.el7.x86_64                                                                                18/20 
  清理        : device-mapper-persistent-data-0.7.3-3.el7.x86_64                                                                          19/20 
  清理        : libxml2-2.9.1-6.el7_2.3.x86_64                                                                                            20/20 
  验证中      : 7:lvm2-2.02.187-6.el7_9.5.x86_64                                                                                           1/20 
  验证中      : python-chardet-2.2.1-3.el7.noarch                                                                                          2/20 
  验证中      : libxml2-2.9.1-6.el7_9.6.x86_64                                                                                             3/20 
  验证中      : 7:lvm2-libs-2.02.187-6.el7_9.5.x86_64                                                                                      4/20 
  验证中      : 7:device-mapper-1.02.170-6.el7_9.5.x86_64                                                                                  5/20 
  验证中      : libxml2-python-2.9.1-6.el7_9.6.x86_64                                                                                      6/20 
  验证中      : device-mapper-persistent-data-0.8.5-3.el7_9.2.x86_64                                                                       7/20 
  验证中      : 7:device-mapper-event-1.02.170-6.el7_9.5.x86_64                                                                            8/20 
  验证中      : python-kitchen-1.1.1-5.el7.noarch                                                                                          9/20 
  验证中      : 7:device-mapper-libs-1.02.170-6.el7_9.5.x86_64                                                                            10/20 
  验证中      : yum-utils-1.1.31-54.el7_8.noarch                                                                                          11/20 
  验证中      : 7:device-mapper-event-libs-1.02.170-6.el7_9.5.x86_64                                                                      12/20 
  验证中      : device-mapper-persistent-data-0.7.3-3.el7.x86_64                                                                          13/20 
  验证中      : 7:device-mapper-event-libs-1.02.146-4.el7.x86_64                                                                          14/20 
  验证中      : libxml2-2.9.1-6.el7_2.3.x86_64                                                                                            15/20 
  验证中      : 7:device-mapper-1.02.146-4.el7.x86_64                                                                                     16/20 
  验证中      : 7:device-mapper-libs-1.02.146-4.el7.x86_64                                                                                17/20 
  验证中      : 7:device-mapper-event-1.02.146-4.el7.x86_64                                                                               18/20 
  验证中      : 7:lvm2-libs-2.02.177-4.el7.x86_64                                                                                         19/20 
  验证中      : 7:lvm2-2.02.177-4.el7.x86_64                                                                                              20/20 

已安装:
  yum-utils.noarch 0:1.1.31-54.el7_8                                                                                                            

作为依赖被安装:
  libxml2-python.x86_64 0:2.9.1-6.el7_9.6           python-chardet.noarch 0:2.2.1-3.el7           python-kitchen.noarch 0:1.1.1-5.el7          

更新完毕:
  device-mapper-persistent-data.x86_64 0:0.8.5-3.el7_9.2                            lvm2.x86_64 7:2.02.187-6.el7_9.5                           

作为依赖被升级:
  device-mapper.x86_64 7:1.02.170-6.el7_9.5                                 device-mapper-event.x86_64 7:1.02.170-6.el7_9.5                     
  device-mapper-event-libs.x86_64 7:1.02.170-6.el7_9.5                      device-mapper-libs.x86_64 7:1.02.170-6.el7_9.5                      
  libxml2.x86_64 0:2.9.1-6.el7_9.6                                          lvm2-libs.x86_64 7:2.02.187-6.el7_9.5                               

完毕!
复制代码

 

2、添加docker软件源信息

[root@Template-CentOS7-7 ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
已加载插件:fastestmirror
adding repo from: https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file https://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

 

3、修改软件源地址为阿里源

复制代码
[root@Template-CentOS7-7 ~]# sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
[root@Template-CentOS7-7 ~]# yum makecache fast
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
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/7/x86_64/updateinfo                                                                              |   55 B  00:00:00     
(2/2): docker-ce-stable/7/x86_64/primary_db                                                                              | 104 kB  00:00:00     
元数据缓存已建立
复制代码

 

4、查看docker可用版本信息,选择指定版本安装docker服务

复制代码
# 官方软件源默认启用了最新的软件,您可以通过编辑软件源的方式获取各个版本的软件包。例如官方并没有将测试版本的软件源置为可用,您可以通过以下方式开启。同理可以开启各种测试版本等。
# vim /etc/yum.repos.d/docker-ce.repo
#   将[docker-ce-test]下方的enabled=0修改为enabled=1

[root@Template-CentOS7-7 ~]# vim /etc/yum.repos.d/docker-ce.repo [docker-ce-test] name=Docker CE Test - $basearch baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/test enabled=1 gpgcheck=1 [root@Template-CentOS7-7 ~]# yum list docker-ce --showduplicates 已加载插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com docker-ce-stable | 3.5 kB 00:00:00 docker-ce-test | 3.5 kB 00:00:00 (1/2): docker-ce-test/7/x86_64/updateinfo | 55 B 00:00:00 (2/2): docker-ce-test/7/x86_64/primary_db | 201 kB 00:00:00 可安装的软件包 docker-ce.x86_64 17.03.0.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.1.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.2.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.03.3.ce-0.1.rc1.el7 docker-ce-test docker-ce.x86_64 17.03.3.ce-1.el7 docker-ce-stable docker-ce.x86_64 17.03.3.ce-1.el7 docker-ce-test docker-ce.x86_64 17.04.0.ce-0.1.rc1.el7.centos docker-ce-test docker-ce.x86_64 17.04.0.ce-0.2.rc2.el7.centos docker-ce-test docker-ce.x86_64 17.05.0.ce-0.1.rc1.el7.centos docker-ce-test docker-ce.x86_64 17.05.0.ce-0.2.rc2.el7.centos docker-ce-test docker-ce.x86_64 17.05.0.ce-0.3.rc3.el7.centos docker-ce-test docker-ce.x86_64 17.06.0.ce-0.1.rc1.el7.centos docker-ce-test docker-ce.x86_64 17.06.0.ce-0.2.rc2.el7.centos docker-ce-test docker-ce.x86_64 17.06.0.ce-0.3.rc3.el7.centos docker-ce-test docker-ce.x86_64 17.06.0.ce-0.4.rc4.el7.centos docker-ce-test docker-ce.x86_64 17.06.0.ce-0.5.rc5.el7.centos docker-ce-test docker-ce.x86_64 17.06.0.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.06.0.ce-1.el7.centos docker-ce-test docker-ce.x86_64 17.06.1.ce-0.1.rc1.el7.centos docker-ce-test docker-ce.x86_64 17.06.1.ce-0.2.rc2.el7.centos docker-ce-test docker-ce.x86_64 17.06.1.ce-0.3.rc3.el7.centos docker-ce-test docker-ce.x86_64 17.06.1.ce-0.4.rc4.el7.centos docker-ce-test docker-ce.x86_64 17.06.1.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.06.1.ce-1.el7.centos docker-ce-test docker-ce.x86_64 17.06.2.ce-0.1.rc1.el7.centos docker-ce-test docker-ce.x86_64 17.06.2.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.06.2.ce-1.el7.centos docker-ce-test docker-ce.x86_64 17.07.0.ce-0.1.rc1.el7.centos docker-ce-test docker-ce.x86_64 17.07.0.ce-0.2.rc2.el7.centos docker-ce-test docker-ce.x86_64 17.07.0.ce-0.3.rc3.el7.centos docker-ce-test docker-ce.x86_64 17.07.0.ce-0.4.rc4.el7.centos docker-ce-test docker-ce.x86_64 17.07.0.ce-1.el7.centos docker-ce-test docker-ce.x86_64 17.09.0.ce-0.1.rc1.el7.centos docker-ce-test docker-ce.x86_64 17.09.0.ce-0.2.rc2.el7.centos docker-ce-test docker-ce.x86_64 17.09.0.ce-0.3.rc3.el7.centos docker-ce-test docker-ce.x86_64 17.09.0.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.09.0.ce-1.el7.centos docker-ce-test docker-ce.x86_64 17.09.1.ce-0.1.rc1.el7.centos docker-ce-test docker-ce.x86_64 17.09.1.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.09.1.ce-1.el7.centos docker-ce-test docker-ce.x86_64 17.10.0.ce-0.1.rc1.el7.centos docker-ce-test docker-ce.x86_64 17.10.0.ce-0.2.rc2.el7.centos docker-ce-test docker-ce.x86_64 17.10.0.ce-1.el7.centos docker-ce-test docker-ce.x86_64 17.11.0.ce-0.1.rc1.el7.centos docker-ce-test docker-ce.x86_64 17.11.0.ce-0.2.rc2.el7.centos docker-ce-test docker-ce.x86_64 17.11.0.ce-0.3.rc3.el7.centos docker-ce-test docker-ce.x86_64 17.11.0.ce-0.4.rc4.el7.centos docker-ce-test docker-ce.x86_64 17.11.0.ce-1.el7.centos docker-ce-test docker-ce.x86_64 17.12.0.ce-0.1.rc1.el7.centos docker-ce-test docker-ce.x86_64 17.12.0.ce-0.2.rc2.el7.centos docker-ce-test docker-ce.x86_64 17.12.0.ce-0.3.rc3.el7.centos docker-ce-test docker-ce.x86_64 17.12.0.ce-0.4.rc4.el7.centos docker-ce-test docker-ce.x86_64 17.12.0.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.12.0.ce-1.el7.centos docker-ce-test docker-ce.x86_64 17.12.1.ce-0.1.rc1.el7.centos docker-ce-test docker-ce.x86_64 17.12.1.ce-0.2.rc2.el7.centos docker-ce-test docker-ce.x86_64 17.12.1.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.12.1.ce-1.el7.centos docker-ce-test docker-ce.x86_64 18.01.0.ce-0.1.rc1.el7.centos docker-ce-test docker-ce.x86_64 18.01.0.ce-1.el7.centos docker-ce-test docker-ce.x86_64 18.02.0.ce-0.1.rc1.el7.centos docker-ce-test docker-ce.x86_64 18.02.0.ce-0.2.rc2.el7.centos docker-ce-test docker-ce.x86_64 18.02.0.ce-1.el7.centos docker-ce-test docker-ce.x86_64 18.03.0.ce-0.1.rc1.el7.centos docker-ce-test docker-ce.x86_64 18.03.0.ce-0.2.rc2.el7.centos docker-ce-test docker-ce.x86_64 18.03.0.ce-0.3.rc3.el7.centos docker-ce-test docker-ce.x86_64 18.03.0.ce-0.4.rc4.el7.centos docker-ce-test docker-ce.x86_64 18.03.0.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 18.03.0.ce-1.el7.centos docker-ce-test docker-ce.x86_64 18.03.1.ce-0.1.rc1.el7.centos docker-ce-test docker-ce.x86_64 18.03.1.ce-0.2.rc2.el7.centos docker-ce-test docker-ce.x86_64 18.03.1.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 18.03.1.ce-1.el7.centos docker-ce-test docker-ce.x86_64 18.04.0.ce-2.1.rc1.el7.centos docker-ce-test docker-ce.x86_64 18.04.0.ce-2.2.rc2.el7.centos docker-ce-test docker-ce.x86_64 18.04.0.ce-3.el7.centos docker-ce-test docker-ce.x86_64 18.05.0.ce-2.1.rc1.el7.centos docker-ce-test docker-ce.x86_64 18.05.0.ce-3.el7.centos docker-ce-test docker-ce.x86_64 18.06.0.ce-2.1.rc1.el7 docker-ce-test docker-ce.x86_64 18.06.0.ce-2.2.rc2.el7 docker-ce-test docker-ce.x86_64 18.06.0.ce-2.3.rc3.el7 docker-ce-test docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-test docker-ce.x86_64 18.06.1.ce-2.1.rc1.el7 docker-ce-test docker-ce.x86_64 18.06.1.ce-2.2.rc2.el7 docker-ce-test docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-test docker-ce.x86_64 18.06.2.ce-3.el7 docker-ce-stable docker-ce.x86_64 18.06.2.ce-3.el7 docker-ce-test docker-ce.x86_64 18.06.3.ce-3.el7 docker-ce-stable docker-ce.x86_64 18.06.3.ce-3.el7 docker-ce-test docker-ce.x86_64 2:18.09.0.ce-0.0.tp0.el7 docker-ce-test docker-ce.x86_64 2:18.09.0.ce-0.3.tp3.el7 docker-ce-test docker-ce.x86_64 2:18.09.0.ce-0.4.tp4.el7 docker-ce-test docker-ce.x86_64 2:18.09.0.ce-0.5.tp5.el7 docker-ce-test docker-ce.x86_64 2:18.09.0.ce-0.6.tp6.el7 docker-ce-test docker-ce.x86_64 2:18.09.0.ce-1.1.beta1.el7 docker-ce-test docker-ce.x86_64 3:18.09.0-1.3.beta3.el7 docker-ce-test docker-ce.x86_64 3:18.09.0-1.5.beta5.el7 docker-ce-test docker-ce.x86_64 3:18.09.0-2.1.rc1.el7 docker-ce-test docker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.0-3.el7 docker-ce-test docker-ce.x86_64 3:18.09.1-1.1.beta1.el7 docker-ce-test docker-ce.x86_64 3:18.09.1-1.2.beta2.el7 docker-ce-test docker-ce.x86_64 3:18.09.1-2.1.rc1.el7 docker-ce-test docker-ce.x86_64 3:18.09.1-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.1-3.el7 docker-ce-test docker-ce.x86_64 3:18.09.2-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.2-3.el7 docker-ce-test docker-ce.x86_64 3:18.09.3-2.1.rc1.el7 docker-ce-test docker-ce.x86_64 3:18.09.3-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.3-3.el7 docker-ce-test docker-ce.x86_64 3:18.09.4-2.1.rc1.el7 docker-ce-test docker-ce.x86_64 3:18.09.4-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.4-3.el7 docker-ce-test docker-ce.x86_64 3:18.09.5-2.1.rc1.el7 docker-ce-test docker-ce.x86_64 3:18.09.5-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.5-3.el7 docker-ce-test docker-ce.x86_64 3:18.09.6-2.1.rc1.el7 docker-ce-test docker-ce.x86_64 3:18.09.6-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.6-3.el7 docker-ce-test docker-ce.x86_64 3:18.09.7-2.1.rc1.el7 docker-ce-test docker-ce.x86_64 3:18.09.7-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.7-3.el7 docker-ce-test docker-ce.x86_64 3:18.09.8-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.8-3.el7 docker-ce-test docker-ce.x86_64 3:18.09.9-1.1.beta1.el7 docker-ce-test docker-ce.x86_64 3:18.09.9-2.1.rc1.el7 docker-ce-test docker-ce.x86_64 3:18.09.9-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.9-3.el7 docker-ce-test docker-ce.x86_64 3:19.03.0-1.1.beta1.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.3.beta3.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.5.beta5.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-2.3.rc3.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-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-test docker-ce.x86_64 3:19.03.2-1.1.beta1.el7 docker-ce-test docker-ce.x86_64 3:19.03.2-2.1.rc1.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-test docker-ce.x86_64 3:19.03.3-1.1.beta1.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-2.1.rc1.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-test docker-ce.x86_64 3:19.03.4-2.1.rc1.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-test docker-ce.x86_64 3:19.03.5-1.1.beta1.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-2.1.rc1.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-test docker-ce.x86_64 3:19.03.6-2.1.rc1.el7 docker-ce-test docker-ce.x86_64 3:19.03.6-2.2.rc2.el7 docker-ce-test docker-ce.x86_64 3:19.03.6-3.el7 docker-ce-stable docker-ce.x86_64 3:19.03.6-3.el7 docker-ce-test docker-ce.x86_64 3:19.03.7-3.el7 docker-ce-stable docker-ce.x86_64 3:19.03.7-3.el7 docker-ce-test docker-ce.x86_64 3:19.03.8-3.el7 docker-ce-stable docker-ce.x86_64 3:19.03.8-3.el7 docker-ce-test docker-ce.x86_64 3:19.03.9-3.el7 docker-ce-stable docker-ce.x86_64 3:19.03.9-3.el7 docker-ce-test docker-ce.x86_64 3:19.03.10-3.el7 docker-ce-stable docker-ce.x86_64 3:19.03.10-3.el7 docker-ce-test docker-ce.x86_64 3:19.03.11-3.el7 docker-ce-stable docker-ce.x86_64 3:19.03.11-3.el7 docker-ce-test docker-ce.x86_64 3:19.03.12-3.el7 docker-ce-stable docker-ce.x86_64 3:19.03.12-3.el7 docker-ce-test docker-ce.x86_64 3:19.03.13-1.2.beta2.el7 docker-ce-test docker-ce.x86_64 3:19.03.13-3.el7 docker-ce-stable docker-ce.x86_64 3:19.03.13-3.el7 docker-ce-test docker-ce.x86_64 3:19.03.14-3.el7 docker-ce-stable docker-ce.x86_64 3:19.03.14-3.el7 docker-ce-test docker-ce.x86_64 3:19.03.15-3.el7 docker-ce-stable docker-ce.x86_64 3:19.03.15-3.el7 docker-ce-test docker-ce.x86_64 3:20.10.0-1.1.beta1.el7 docker-ce-test docker-ce.x86_64 3:20.10.0-2.1.rc1.el7 docker-ce-test docker-ce.x86_64 3:20.10.0-2.2.rc2.el7 docker-ce-test docker-ce.x86_64 3:20.10.0-3.el7 docker-ce-stable docker-ce.x86_64 3:20.10.0-3.el7 docker-ce-test docker-ce.x86_64 3:20.10.1-3.el7 docker-ce-stable docker-ce.x86_64 3:20.10.1-3.el7 docker-ce-test docker-ce.x86_64 3:20.10.2-3.el7 docker-ce-stable docker-ce.x86_64 3:20.10.2-3.el7 docker-ce-test docker-ce.x86_64 3:20.10.3-3.el7 docker-ce-stable docker-ce.x86_64 3:20.10.3-3.el7 docker-ce-test docker-ce.x86_64 3:20.10.4-3.el7 docker-ce-stable docker-ce.x86_64 3:20.10.4-3.el7 docker-ce-test docker-ce.x86_64 3:20.10.5-3.el7 docker-ce-stable docker-ce.x86_64 3:20.10.5-3.el7 docker-ce-test docker-ce.x86_64 3:20.10.6-3.el7 docker-ce-stable docker-ce.x86_64 3:20.10.6-3.el7 docker-ce-test docker-ce.x86_64 3:20.10.7-3.el7 docker-ce-stable docker-ce.x86_64 3:20.10.7-3.el7 docker-ce-test docker-ce.x86_64 3:20.10.8-3.el7 docker-ce-stable docker-ce.x86_64 3:20.10.8-3.el7 docker-ce-test docker-ce.x86_64 3:20.10.9-3.el7 docker-ce-stable docker-ce.x86_64 3:20.10.9-3.el7 docker-ce-test docker-ce.x86_64 3:20.10.10-2.1.rc1.el7 docker-ce-test docker-ce.x86_64 3:20.10.10-3.el7 docker-ce-stable docker-ce.x86_64 3:20.10.10-3.el7 docker-ce-test docker-ce.x86_64 3:20.10.11-3.el7 docker-ce-stable docker-ce.x86_64 3:20.10.11-3.el7 docker-ce-test docker-ce.x86_64 3:20.10.12-3.el7 docker-ce-stable docker-ce.x86_64 3:20.10.12-3.el7 docker-ce-test docker-ce.x86_64 3:20.10.13-3.el7 docker-ce-stable docker-ce.x86_64 3:20.10.13-3.el7 docker-ce-test docker-ce.x86_64 3:20.10.14-3.el7 docker-ce-stable docker-ce.x86_64 3:20.10.14-3.el7 docker-ce-test docker-ce.x86_64 3:20.10.15-3.el7 docker-ce-stable docker-ce.x86_64 3:20.10.15-3.el7 docker-ce-test docker-ce.x86_64 3:20.10.16-3.el7 docker-ce-stable docker-ce.x86_64 3:20.10.16-3.el7 docker-ce-test docker-ce.x86_64 3:20.10.17-3.el7 docker-ce-stable docker-ce.x86_64 3:20.10.17-3.el7 docker-ce-test docker-ce.x86_64 3:20.10.18-3.el7 docker-ce-stable docker-ce.x86_64 3:20.10.18-3.el7 docker-ce-test docker-ce.x86_64 3:20.10.19-3.el7 docker-ce-stable docker-ce.x86_64 3:20.10.19-3.el7 docker-ce-test docker-ce.x86_64 3:20.10.20-3.el7 docker-ce-stable docker-ce.x86_64 3:20.10.20-3.el7 docker-ce-test docker-ce.x86_64 3:20.10.21-3.el7 docker-ce-stable docker-ce.x86_64 3:20.10.21-3.el7 docker-ce-test docker-ce.x86_64 3:20.10.22-3.el7 docker-ce-stable docker-ce.x86_64 3:20.10.22-3.el7 docker-ce-test docker-ce.x86_64 3:20.10.23-3.el7 docker-ce-stable docker-ce.x86_64 3:20.10.23-3.el7 docker-ce-test docker-ce.x86_64 3:20.10.24-3.el7 docker-ce-stable docker-ce.x86_64 3:20.10.24-3.el7 docker-ce-test docker-ce.x86_64 3:22.06.0~beta.0-1.el7 docker-ce-test docker-ce.x86_64 3:23.0.0~beta.1-1.el7 docker-ce-test docker-ce.x86_64 3:23.0.0~rc.1-1.el7 docker-ce-test docker-ce.x86_64 3:23.0.0~rc.2-1.el7 docker-ce-test docker-ce.x86_64 3:23.0.0~rc.3-1.el7 docker-ce-test docker-ce.x86_64 3:23.0.0~rc.4-1.el7 docker-ce-test docker-ce.x86_64 3:23.0.0-1.el7 docker-ce-stable docker-ce.x86_64 3:23.0.0-1.el7 docker-ce-test docker-ce.x86_64 3:23.0.1-1.el7 docker-ce-stable docker-ce.x86_64 3:23.0.1-1.el7 docker-ce-test docker-ce.x86_64 3:23.0.2-1.el7 docker-ce-stable docker-ce.x86_64 3:23.0.2-1.el7 docker-ce-test docker-ce.x86_64 3:23.0.3-1.el7 docker-ce-stable docker-ce.x86_64 3:23.0.3-1.el7 docker-ce-test docker-ce.x86_64 3:23.0.4-1.el7 docker-ce-stable docker-ce.x86_64 3:23.0.4-1.el7 docker-ce-test docker-ce.x86_64 3:24.0.0~beta.1-1.el7 docker-ce-test docker-ce.x86_64 3:24.0.0~beta.2-1.el7 docker-ce-test [root@Template-CentOS7-7 ~]# yum install docker-ce-19.03.15-3.el7 -y 已加载插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com 正在解决依赖关系 --> 正在检查事务 ---> 软件包 docker-ce.x86_64.3.19.03.15-3.el7 将被 安装 --> 正在处理依赖关系 container-selinux >= 2:2.74,它被软件包 3:docker-ce-19.03.15-3.el7.x86_64 需要 --> 正在处理依赖关系 containerd.io >= 1.2.2-3,它被软件包 3:docker-ce-19.03.15-3.el7.x86_64 需要 --> 正在处理依赖关系 docker-ce-cli,它被软件包 3:docker-ce-19.03.15-3.el7.x86_64 需要 --> 正在处理依赖关系 libcgroup,它被软件包 3:docker-ce-19.03.15-3.el7.x86_64 需要 --> 正在检查事务 ---> 软件包 container-selinux.noarch.2.2.119.2-1.911c772.el7_8 将被 安装 --> 正在处理依赖关系 selinux-policy-targeted >= 3.13.1-216.el7,它被软件包 2:container-selinux-2.119.2-1.911c772.el7_8.noarch 需要 --> 正在处理依赖关系 selinux-policy-base >= 3.13.1-216.el7,它被软件包 2:container-selinux-2.119.2-1.911c772.el7_8.noarch 需要 --> 正在处理依赖关系 selinux-policy >= 3.13.1-216.el7,它被软件包 2:container-selinux-2.119.2-1.911c772.el7_8.noarch 需要 --> 正在处理依赖关系 policycoreutils-python,它被软件包 2:container-selinux-2.119.2-1.911c772.el7_8.noarch 需要 ---> 软件包 containerd.io.x86_64.0.1.6.20-3.1.el7 将被 安装 ---> 软件包 docker-ce-cli.x86_64.1.24.0.0~beta.2-1.el7 将被 安装 --> 正在处理依赖关系 docker-buildx-plugin,它被软件包 1:docker-ce-cli-24.0.0~beta.2-1.el7.x86_64 需要 --> 正在处理依赖关系 docker-compose-plugin,它被软件包 1:docker-ce-cli-24.0.0~beta.2-1.el7.x86_64 需要 ---> 软件包 libcgroup.x86_64.0.0.41-21.el7 将被 安装 --> 正在检查事务 ---> 软件包 docker-buildx-plugin.x86_64.0.0.10.4-1.el7 将被 安装 ---> 软件包 docker-compose-plugin.x86_64.0.2.17.2-1.el7 将被 安装 ---> 软件包 policycoreutils-python.x86_64.0.2.5-34.el7 将被 安装 --> 正在处理依赖关系 policycoreutils = 2.5-34.el7,它被软件包 policycoreutils-python-2.5-34.el7.x86_64 需要 --> 正在处理依赖关系 setools-libs >= 3.3.8-4,它被软件包 policycoreutils-python-2.5-34.el7.x86_64 需要 --> 正在处理依赖关系 libsemanage-python >= 2.5-14,它被软件包 policycoreutils-python-2.5-34.el7.x86_64 需要 --> 正在处理依赖关系 audit-libs-python >= 2.1.3-4,它被软件包 policycoreutils-python-2.5-34.el7.x86_64 需要 --> 正在处理依赖关系 python-IPy,它被软件包 policycoreutils-python-2.5-34.el7.x86_64 需要 --> 正在处理依赖关系 libqpol.so.1(VERS_1.4)(64bit),它被软件包 policycoreutils-python-2.5-34.el7.x86_64 需要 --> 正在处理依赖关系 libqpol.so.1(VERS_1.2)(64bit),它被软件包 policycoreutils-python-2.5-34.el7.x86_64 需要 --> 正在处理依赖关系 libapol.so.4(VERS_4.0)(64bit),它被软件包 policycoreutils-python-2.5-34.el7.x86_64 需要 --> 正在处理依赖关系 checkpolicy,它被软件包 policycoreutils-python-2.5-34.el7.x86_64 需要 --> 正在处理依赖关系 libqpol.so.1()(64bit),它被软件包 policycoreutils-python-2.5-34.el7.x86_64 需要 --> 正在处理依赖关系 libapol.so.4()(64bit),它被软件包 policycoreutils-python-2.5-34.el7.x86_64 需要 ---> 软件包 selinux-policy.noarch.0.3.13.1-192.el7 将被 升级 ---> 软件包 selinux-policy.noarch.0.3.13.1-268.el7_9.2 将被 更新 --> 正在处理依赖关系 libsemanage >= 2.5-13,它被软件包 selinux-policy-3.13.1-268.el7_9.2.noarch 需要 ---> 软件包 selinux-policy-targeted.noarch.0.3.13.1-192.el7 将被 升级 ---> 软件包 selinux-policy-targeted.noarch.0.3.13.1-268.el7_9.2 将被 更新 --> 正在检查事务 ---> 软件包 audit-libs-python.x86_64.0.2.8.5-4.el7 将被 安装 --> 正在处理依赖关系 audit-libs(x86-64) = 2.8.5-4.el7,它被软件包 audit-libs-python-2.8.5-4.el7.x86_64 需要 ---> 软件包 checkpolicy.x86_64.0.2.5-8.el7 将被 安装 ---> 软件包 libsemanage.x86_64.0.2.5-11.el7 将被 升级 ---> 软件包 libsemanage.x86_64.0.2.5-14.el7 将被 更新 --> 正在处理依赖关系 libsepol >= 2.5-10,它被软件包 libsemanage-2.5-14.el7.x86_64 需要 --> 正在处理依赖关系 libselinux >= 2.5-14,它被软件包 libsemanage-2.5-14.el7.x86_64 需要 ---> 软件包 libsemanage-python.x86_64.0.2.5-14.el7 将被 安装 ---> 软件包 policycoreutils.x86_64.0.2.5-22.el7 将被 升级 ---> 软件包 policycoreutils.x86_64.0.2.5-34.el7 将被 更新 --> 正在处理依赖关系 libselinux-utils >= 2.5-14,它被软件包 policycoreutils-2.5-34.el7.x86_64 需要 ---> 软件包 python-IPy.noarch.0.0.75-6.el7 将被 安装 ---> 软件包 setools-libs.x86_64.0.3.3.8-4.el7 将被 安装 --> 正在检查事务 ---> 软件包 audit-libs.x86_64.0.2.8.1-3.el7 将被 升级 --> 正在处理依赖关系 audit-libs(x86-64) = 2.8.1-3.el7,它被软件包 audit-2.8.1-3.el7.x86_64 需要 ---> 软件包 audit-libs.x86_64.0.2.8.5-4.el7 将被 更新 ---> 软件包 libselinux.x86_64.0.2.5-12.el7 将被 升级 --> 正在处理依赖关系 libselinux(x86-64) = 2.5-12.el7,它被软件包 libselinux-python-2.5-12.el7.x86_64 需要 ---> 软件包 libselinux.x86_64.0.2.5-15.el7 将被 更新 ---> 软件包 libselinux-utils.x86_64.0.2.5-12.el7 将被 升级 ---> 软件包 libselinux-utils.x86_64.0.2.5-15.el7 将被 更新 ---> 软件包 libsepol.x86_64.0.2.5-8.1.el7 将被 升级 ---> 软件包 libsepol.x86_64.0.2.5-10.el7 将被 更新 --> 正在检查事务 ---> 软件包 audit.x86_64.0.2.8.1-3.el7 将被 升级 ---> 软件包 audit.x86_64.0.2.8.5-4.el7 将被 更新 ---> 软件包 libselinux-python.x86_64.0.2.5-12.el7 将被 升级 ---> 软件包 libselinux-python.x86_64.0.2.5-15.el7 将被 更新 --> 解决依赖关系完成 依赖关系解决 ================================================================================================================================================ Package 架构 版本 源 大小 ================================================================================================================================================ 正在安装: docker-ce x86_64 3:19.03.15-3.el7 docker-ce-stable 24 M 为依赖而安装: audit-libs-python x86_64 2.8.5-4.el7 base 76 k checkpolicy x86_64 2.5-8.el7 base 295 k container-selinux noarch 2:2.119.2-1.911c772.el7_8 extras 40 k containerd.io x86_64 1.6.20-3.1.el7 docker-ce-stable 34 M docker-buildx-plugin x86_64 0.10.4-1.el7 docker-ce-stable 12 M docker-ce-cli x86_64 1:24.0.0~beta.2-1.el7 docker-ce-test 13 M docker-compose-plugin x86_64 2.17.2-1.el7 docker-ce-stable 12 M libcgroup x86_64 0.41-21.el7 base 66 k libsemanage-python x86_64 2.5-14.el7 base 113 k policycoreutils-python x86_64 2.5-34.el7 base 457 k python-IPy noarch 0.75-6.el7 base 32 k setools-libs x86_64 3.3.8-4.el7 base 620 k 为依赖而更新: audit x86_64 2.8.5-4.el7 base 256 k audit-libs x86_64 2.8.5-4.el7 base 102 k libselinux x86_64 2.5-15.el7 base 162 k libselinux-python x86_64 2.5-15.el7 base 236 k libselinux-utils x86_64 2.5-15.el7 base 151 k libsemanage x86_64 2.5-14.el7 base 151 k libsepol x86_64 2.5-10.el7 base 297 k policycoreutils x86_64 2.5-34.el7 base 917 k selinux-policy noarch 3.13.1-268.el7_9.2 updates 498 k selinux-policy-targeted noarch 3.13.1-268.el7_9.2 updates 7.0 M 事务概要 ================================================================================================================================================ 安装 1 软件包 (+12 依赖软件包) 升级 ( 10 依赖软件包) 总下载量:106 M Downloading packages: Delta RPMs disabled because /usr/bin/applydeltarpm not installed. (1/23): audit-libs-2.8.5-4.el7.x86_64.rpm | 102 kB 00:00:01 (2/23): audit-libs-python-2.8.5-4.el7.x86_64.rpm | 76 kB 00:00:00 (3/23): audit-2.8.5-4.el7.x86_64.rpm | 256 kB 00:00:01 (4/23): checkpolicy-2.5-8.el7.x86_64.rpm | 295 kB 00:00:00 (5/23): 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-buildx-plugin-0.10.4-1.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY docker-buildx-plugin-0.10.4-1.el7.x86_64.rpm 的公钥尚未安装 (6/23): docker-buildx-plugin-0.10.4-1.el7.x86_64.rpm | 12 MB 00:00:06 docker-ce-cli-24.0.0~beta.2-1.el7.x86_64.rpm 的公钥尚未安装1% [============================- ] 4.9 MB/s | 65 MB 00:00:08 ETA (7/23): docker-ce-cli-24.0.0~beta.2-1.el7.x86_64.rpm | 13 MB 00:00:07 (8/23): containerd.io-1.6.20-3.1.el7.x86_64.rpm | 34 MB 00:00:18 (9/23): libcgroup-0.41-21.el7.x86_64.rpm | 66 kB 00:00:00 (10/23): libselinux-2.5-15.el7.x86_64.rpm | 162 kB 00:00:00 (11/23): libselinux-python-2.5-15.el7.x86_64.rpm | 236 kB 00:00:00 (12/23): libselinux-utils-2.5-15.el7.x86_64.rpm | 151 kB 00:00:00 (13/23): libsemanage-2.5-14.el7.x86_64.rpm | 151 kB 00:00:00 (14/23): libsemanage-python-2.5-14.el7.x86_64.rpm | 113 kB 00:00:00 (15/23): libsepol-2.5-10.el7.x86_64.rpm | 297 kB 00:00:00 (16/23): policycoreutils-python-2.5-34.el7.x86_64.rpm | 457 kB 00:00:00 (17/23): python-IPy-0.75-6.el7.noarch.rpm | 32 kB 00:00:00 (18/23): policycoreutils-2.5-34.el7.x86_64.rpm | 917 kB 00:00:00 (19/23): selinux-policy-3.13.1-268.el7_9.2.noarch.rpm | 498 kB 00:00:00 (20/23): setools-libs-3.3.8-4.el7.x86_64.rpm | 620 kB 00:00:00 (21/23): docker-ce-19.03.15-3.el7.x86_64.rpm | 24 MB 00:00:13 (22/23): selinux-policy-targeted-3.13.1-268.el7_9.2.noarch.rpm | 7.0 MB 00:00:02 (23/23): docker-compose-plugin-2.17.2-1.el7.x86_64.rpm | 12 MB 00:00:05 ------------------------------------------------------------------------------------------------------------------------------------------------ 总计 4.2 MB/s | 106 MB 00:00:25 从 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 正在更新 : libsepol-2.5-10.el7.x86_64 1/33 正在更新 : libselinux-2.5-15.el7.x86_64 2/33 正在更新 : audit-libs-2.8.5-4.el7.x86_64 3/33 正在更新 : libsemanage-2.5-14.el7.x86_64 4/33 正在更新 : libselinux-utils-2.5-15.el7.x86_64 5/33 正在更新 : policycoreutils-2.5-34.el7.x86_64 6/33 正在更新 : selinux-policy-3.13.1-268.el7_9.2.noarch 7/33 正在安装 : libcgroup-0.41-21.el7.x86_64 8/33 正在更新 : selinux-policy-targeted-3.13.1-268.el7_9.2.noarch 9/33 正在安装 : libsemanage-python-2.5-14.el7.x86_64 10/33 正在安装 : audit-libs-python-2.8.5-4.el7.x86_64 11/33 正在安装 : setools-libs-3.3.8-4.el7.x86_64 12/33 正在更新 : libselinux-python-2.5-15.el7.x86_64 13/33 正在安装 : docker-compose-plugin-2.17.2-1.el7.x86_64 14/33 正在安装 : python-IPy-0.75-6.el7.noarch 15/33 正在安装 : docker-buildx-plugin-0.10.4-1.el7.x86_64 16/33 正在安装 : 1:docker-ce-cli-24.0.0~beta.2-1.el7.x86_64 17/33 正在安装 : checkpolicy-2.5-8.el7.x86_64 18/33 正在安装 : policycoreutils-python-2.5-34.el7.x86_64 19/33 正在安装 : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch 20/33 setsebool: SELinux is disabled. 正在安装 : containerd.io-1.6.20-3.1.el7.x86_64 21/33 正在安装 : 3:docker-ce-19.03.15-3.el7.x86_64 22/33 正在更新 : audit-2.8.5-4.el7.x86_64 23/33 清理 : selinux-policy-targeted-3.13.1-192.el7.noarch 24/33 清理 : selinux-policy-3.13.1-192.el7.noarch 25/33 清理 : policycoreutils-2.5-22.el7.x86_64 26/33 清理 : libsemanage-2.5-11.el7.x86_64 27/33 清理 : libselinux-utils-2.5-12.el7.x86_64 28/33 清理 : libselinux-python-2.5-12.el7.x86_64 29/33 清理 : libselinux-2.5-12.el7.x86_64 30/33 清理 : audit-2.8.1-3.el7.x86_64 31/33 清理 : audit-libs-2.8.1-3.el7.x86_64 32/33 清理 : libsepol-2.5-8.1.el7.x86_64 33/33 验证中 : libselinux-2.5-15.el7.x86_64 1/33 验证中 : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch 2/33 验证中 : selinux-policy-targeted-3.13.1-268.el7_9.2.noarch 3/33 验证中 : audit-libs-2.8.5-4.el7.x86_64 4/33 验证中 : checkpolicy-2.5-8.el7.x86_64 5/33 验证中 : policycoreutils-2.5-34.el7.x86_64 6/33 验证中 : docker-buildx-plugin-0.10.4-1.el7.x86_64 7/33 验证中 : python-IPy-0.75-6.el7.noarch 8/33 验证中 : libselinux-utils-2.5-15.el7.x86_64 9/33 验证中 : policycoreutils-python-2.5-34.el7.x86_64 10/33 验证中 : setools-libs-3.3.8-4.el7.x86_64 11/33 验证中 : audit-2.8.5-4.el7.x86_64 12/33 验证中 : libsemanage-python-2.5-14.el7.x86_64 13/33 验证中 : libsemanage-2.5-14.el7.x86_64 14/33 验证中 : libselinux-python-2.5-15.el7.x86_64 15/33 验证中 : libsepol-2.5-10.el7.x86_64 16/33 验证中 : containerd.io-1.6.20-3.1.el7.x86_64 17/33 验证中 : selinux-policy-3.13.1-268.el7_9.2.noarch 18/33 验证中 : audit-libs-python-2.8.5-4.el7.x86_64 19/33 验证中 : 1:docker-ce-cli-24.0.0~beta.2-1.el7.x86_64 20/33 验证中 : 3:docker-ce-19.03.15-3.el7.x86_64 21/33 验证中 : docker-compose-plugin-2.17.2-1.el7.x86_64 22/33 验证中 : libcgroup-0.41-21.el7.x86_64 23/33 验证中 : libsemanage-2.5-11.el7.x86_64 24/33 验证中 : libselinux-python-2.5-12.el7.x86_64 25/33 验证中 : audit-libs-2.8.1-3.el7.x86_64 26/33 验证中 : policycoreutils-2.5-22.el7.x86_64 27/33 验证中 : libsepol-2.5-8.1.el7.x86_64 28/33 验证中 : audit-2.8.1-3.el7.x86_64 29/33 验证中 : selinux-policy-targeted-3.13.1-192.el7.noarch 30/33 验证中 : selinux-policy-3.13.1-192.el7.noarch 31/33 验证中 : libselinux-2.5-12.el7.x86_64 32/33 验证中 : libselinux-utils-2.5-12.el7.x86_64 33/33 已安装: docker-ce.x86_64 3:19.03.15-3.el7 作为依赖被安装: audit-libs-python.x86_64 0:2.8.5-4.el7 checkpolicy.x86_64 0:2.5-8.el7 container-selinux.noarch 2:2.119.2-1.911c772.el7_8 containerd.io.x86_64 0:1.6.20-3.1.el7 docker-buildx-plugin.x86_64 0:0.10.4-1.el7 docker-ce-cli.x86_64 1:24.0.0~beta.2-1.el7 docker-compose-plugin.x86_64 0:2.17.2-1.el7 libcgroup.x86_64 0:0.41-21.el7 libsemanage-python.x86_64 0:2.5-14.el7 policycoreutils-python.x86_64 0:2.5-34.el7 python-IPy.noarch 0:0.75-6.el7 setools-libs.x86_64 0:3.3.8-4.el7 作为依赖被升级: audit.x86_64 0:2.8.5-4.el7 audit-libs.x86_64 0:2.8.5-4.el7 libselinux.x86_64 0:2.5-15.el7 libselinux-python.x86_64 0:2.5-15.el7 libselinux-utils.x86_64 0:2.5-15.el7 libsemanage.x86_64 0:2.5-14.el7 libsepol.x86_64 0:2.5-10.el7 policycoreutils.x86_64 0:2.5-34.el7 selinux-policy.noarch 0:3.13.1-268.el7_9.2 selinux-policy-targeted.noarch 0:3.13.1-268.el7_9.2 完毕!
复制代码

 

5、启用docker服务

[root@Template-CentOS7-7 ~]# systemctl enable --now docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

 

6、查看docker版本

复制代码
[root@Template-CentOS7-7 ~]# docker version
Client: Docker Engine - Community
 Version:           24.0.0-beta.2
 API version:       1.40 (downgraded from 1.43)
 Go version:        go1.20.3
 Git commit:        67c4570
 Built:             Fri Apr 14 10:31:10 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          19.03.15
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       99e3ed8919
  Built:            Sat Jan 30 03:16:33 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.20
  GitCommit:        2806fc1057397dbaeefbea0e4e17bddfbd388f38
 runc:
  Version:          1.1.5
  GitCommit:        v1.1.5-0-gf19387a
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683
复制代码

 

7、启动一个容器

[root@Template-CentOS7-7 ~]# docker run alpine
Unable to find image 'alpine:latest' locally
latest: Pulling from library/alpine
f56be85fc22e: Pull complete 
Digest: sha256:124c7d2707904eea7431fffe91522a01e5a861a624ee31d03372cc1d138a3126
Status: Downloaded newer image for alpine:latest
[root@Template-CentOS7-7 ~]# 

 

 

三、Linux 编译安装Docker

官方源码包下载地址:https://download.docker.com/linux/

阿里云源码包下载地址:https://mirrors.aliyun.com/docker-ce/linux/static/stable/x86_64/

1、下载源码包

复制代码
[root@Template-CentOS7-7 ~]# wget https://mirrors.aliyun.com/docker-ce/linux/static/stable/x86_64/docker-19.03.15.tgz
--2023-04-24 17:04:19--  https://mirrors.aliyun.com/docker-ce/linux/static/stable/x86_64/docker-19.03.15.tgz
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 120.241.235.124, 120.241.235.122, 120.241.235.127, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|120.241.235.124|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:62436240 (60M) [application/x-compressed-tar]
正在保存至: “docker-19.03.15.tgz”

100%[======================================================================================================>] 62,436,240   546KB/s 用时 2m 2s  

2023-04-24 17:06:22 (498 KB/s) - 已保存 “docker-19.03.15.tgz” [62436240/62436240])

[root@Template-CentOS7-7 ~]# ls
anaconda-ks.cfg  docker-19.03.15.tgz
复制代码

 

2、解压文件

复制代码
[root@Template-CentOS7-7 ~]# tar zxf docker-19.03.15.tgz 
[root@Template-CentOS7-7 ~]# ls
anaconda-ks.cfg  docker  docker-19.03.15.tgz
[root@Template-CentOS7-7 ~]# tree docker
docker
├── containerd
├── containerd-shim
├── ctr
├── docker
├── dockerd
├── docker-init
├── docker-proxy
└── runc

0 directories, 8 files
复制代码

 

3、将二进制文件拷贝至 /usr/bin

[root@Template-CentOS7-7 ~]# cp -a docker/* /usr/bin/

 

4、启动dockerd服务,查看docker版本

复制代码
[root@Template-CentOS7-7 ~]# dockerd &> /dev/null &
[2] 1530
[root@Template-CentOS7-7 ~]# docker version
Client: Docker Engine - Community
 Version:           19.03.15
 API version:       1.40
 Go version:        go1.13.15
 Git commit:        99e3ed8
 Built:             Sat Jan 30 03:11:43 2021
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.15
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       99e3ed8
  Built:            Sat Jan 30 03:18:13 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.3.9
  GitCommit:        ea765aba0d05254012b0b9e595e995c09186427f
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683
[2]+  退出 1                dockerd &>/dev/null
复制代码

 

5、运行一个容器进行测试

复制代码
[root@Template-CentOS7-7 ~]# 
[root@Template-CentOS7-7 ~]# docker run busybox
Unable to find image 'busybox:latest' locally
latest: Pulling from library/busybox
4b35f584bb4f: Pull complete 
Digest: sha256:b5d6fe0712636ceb7430189de28819e195e8966372edfc2d9409d79402a0dc16
Status: Downloaded newer image for busybox:latest
[root@Template-CentOS7-7 ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
650529a50fc1        busybox             "sh"                11 seconds ago      Exited (0) 10 seconds ago                       practical_rosalind
[root@Template-CentOS7-7 ~]# 
复制代码

 

6、配置镜像加速

[root@Template-CentOS7-7 ~]# cat > /etc/docker/daemon.json << EOF
{
  "registry-mirrors": ["镜像加速地址"]
}
EOF

[root@Template-CentOS7-7 ~]# 
复制代码
[root@Template-CentOS7-7 ~]# killall dockerd
[root@Template-CentOS7-7 ~]# dockerd &> /dev/null &
[2] 1798
[1]   完成                  dockerd &>/dev/null
[root@Template-CentOS7-7 ~]# docker pull alpine
Using default tag: latest
latest: Pulling from library/alpine
59bf1c3509f3: Pull complete 
Digest: sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300
Status: Downloaded newer image for alpine:latest
docker.io/library/alpine:latest
[root@Template-CentOS7-7 ~]# 
复制代码

 

 

四、CentOS8 yum安装Podman

1、dnf 安装podman-docker

复制代码
[root@Docker-CentOS8-12 ~]# dnf install podman-docker -y
上次元数据过期检查:0:29:48 前,执行于 2023年04月23日 星期日 20时48分35秒。
依赖关系解决。
================================================================================================================================================
 软件包                           架构                  版本                                                     仓库                      大小
================================================================================================================================================
安装:
 podman-docker                    noarch                3.3.1-9.module_el8.5.0+988+b1f0b741                      AppStream                 56 k
升级:
 container-selinux                noarch                2:2.167.0-1.module_el8.5.0+911+f19012f9                  AppStream                 54 k
 containers-common                noarch                2:1-2.module_el8.5.0+890+6b136101                        AppStream                 79 k
 podman                           x86_64                3.3.1-9.module_el8.5.0+988+b1f0b741                      AppStream                 12 M
 podman-catatonit                 x86_64                3.3.1-9.module_el8.5.0+988+b1f0b741                      AppStream                340 k

事务概要
================================================================================================================================================
安装  1 软件包
升级  4 软件包

总下载:13 M
下载软件包:
(1/5): containers-common-1-2.module_el8.5.0+890+6b136101.noarch.rpm                                             347 kB/s |  79 kB     00:00    
(2/5): container-selinux-2.167.0-1.module_el8.5.0+911+f19012f9.noarch.rpm                                       232 kB/s |  54 kB     00:00    
(3/5): podman-catatonit-3.3.1-9.module_el8.5.0+988+b1f0b741.x86_64.rpm                                          1.5 MB/s | 340 kB     00:00    
(4/5): podman-docker-3.3.1-9.module_el8.5.0+988+b1f0b741.noarch.rpm                                             120 kB/s |  56 kB     00:00    
(5/5): podman-3.3.1-9.module_el8.5.0+988+b1f0b741.x86_64.rpm                                                    7.4 MB/s |  12 MB     00:01    
------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                            6.8 MB/s |  13 MB     00:01     
警告:/var/cache/dnf/AppStream-bf1daca1ea021975/packages/podman-docker-3.3.1-9.module_el8.5.0+988+b1f0b741.noarch.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID 8483c65d: NOKEY
为 AppStream 从 http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official 获取的 repo 密钥未加密
CentOS-8 - AppStream - mirrors.aliyun.com                                                                        16 kB/s | 1.6 kB     00:00    
导入 GPG 公钥 0x8483C65D:
 Userid: "CentOS (CentOS Official Signing Key) <security@centos.org>"
 指纹: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65D
 来自: http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
导入公钥成功
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
  准备中  :                                                                                                                                 1/1 
  运行脚本: container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch                                                                1/1 
  运行脚本: container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch                                                                1/9 
  升级    : container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch                                                                1/9 
  运行脚本: container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch                                                                1/9 
  升级    : containers-common-2:1-2.module_el8.5.0+890+6b136101.noarch                                                                      2/9 
  升级    : podman-catatonit-3.3.1-9.module_el8.5.0+988+b1f0b741.x86_64                                                                     3/9 
  升级    : podman-3.3.1-9.module_el8.5.0+988+b1f0b741.x86_64                                                                               4/9 
  安装    : podman-docker-3.3.1-9.module_el8.5.0+988+b1f0b741.noarch                                                                        5/9 
  清理    : podman-3.0.1-6.module_el8.4.0+781+acf4c33b.x86_64                                                                               6/9 
  清理    : container-selinux-2:2.158.0-1.module_el8.4.0+781+acf4c33b.noarch                                                                7/9 
  运行脚本: container-selinux-2:2.158.0-1.module_el8.4.0+781+acf4c33b.noarch                                                                7/9 
  清理    : containers-common-1:1.2.2-8.module_el8.4.0+781+acf4c33b.x86_64                                                                  8/9 
  清理    : podman-catatonit-3.0.1-6.module_el8.4.0+781+acf4c33b.x86_64                                                                     9/9 
  运行脚本: container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch                                                                9/9 
  运行脚本: podman-catatonit-3.0.1-6.module_el8.4.0+781+acf4c33b.x86_64                                                                     9/9 
  验证    : podman-docker-3.3.1-9.module_el8.5.0+988+b1f0b741.noarch                                                                        1/9 
  验证    : container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch                                                                2/9 
  验证    : container-selinux-2:2.158.0-1.module_el8.4.0+781+acf4c33b.noarch                                                                3/9 
  验证    : containers-common-2:1-2.module_el8.5.0+890+6b136101.noarch                                                                      4/9 
  验证    : containers-common-1:1.2.2-8.module_el8.4.0+781+acf4c33b.x86_64                                                                  5/9 
  验证    : podman-3.3.1-9.module_el8.5.0+988+b1f0b741.x86_64                                                                               6/9 
  验证    : podman-3.0.1-6.module_el8.4.0+781+acf4c33b.x86_64                                                                               7/9 
  验证    : podman-catatonit-3.3.1-9.module_el8.5.0+988+b1f0b741.x86_64                                                                     8/9 
  验证    : podman-catatonit-3.0.1-6.module_el8.4.0+781+acf4c33b.x86_64                                                                     9/9 

已升级:
  container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch          containers-common-2:1-2.module_el8.5.0+890+6b136101.noarch          
  podman-3.3.1-9.module_el8.5.0+988+b1f0b741.x86_64                         podman-catatonit-3.3.1-9.module_el8.5.0+988+b1f0b741.x86_64         
已安装:
  podman-docker-3.3.1-9.module_el8.5.0+988+b1f0b741.noarch                                                                                      

完毕!
[root@Docker-CentOS8-12 ~]# 
复制代码

 

2、查看podman版本

[root@Docker-CentOS8-12 ~]# podman version
Version:      3.3.1
API Version:  3.3.1
Go Version:   go1.16.7
Built:        Wed Nov 10 05:23:56 2021
OS/Arch:      linux/amd64

 

3、修改podman镜像源设置

[root@Docker-CentOS8-12 ~]# cat /etc/containers/registries.conf | grep ^[^#]| grep registries
unqualified-search-registries = ["registry.fedoraproject.org", "registry.access.redhat.com", "registry.centos.org", "docker.io"]
[root@Docker-CentOS8-12 ~]# sed -i.bak '/^unqualified-search-registries =.*/c unqualified-search-registries = ["镜像加速地址","docker.io"]' /etc/containers/registries.conf
[root@Docker-CentOS8-12 ~]# cat /etc/containers/registries.conf | grep ^[^#]| grep registries
unqualified-search-registries = ["镜像加速地址","docker.io"]
复制代码
[root@Docker-CentOS8-12 ~]# podman info
host:
  arch: amd64
  buildahVersion: 1.22.3
  cgroupControllers:
  - cpuset
  - cpu
  - cpuacct
  - blkio
  - memory
  - devices
  - freezer
  - net_cls
  - perf_event
  - net_prio
  - hugetlb
  - pids
  - rdma
  cgroupManager: systemd
  cgroupVersion: v1
  conmon:
    package: conmon-2.0.26-1.module_el8.4.0+781+acf4c33b.x86_64
    path: /usr/bin/conmon
    version: 'conmon version 2.0.26, commit: 76c72c12c83408e6ddaaa7bcd25e96ca20bf9348'
  cpus: 1
  distribution:
    distribution: '"centos"'
    version: "8"
  eventLogger: file
  hostname: Docker-CentOS8-12
  idMappings:
    gidmap: null
    uidmap: null
  kernel: 4.18.0-305.3.1.el8.x86_64
  linkmode: dynamic
  memFree: 225705984
  memTotal: 820391936
  ociRuntime:
    name: runc
    package: runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64
    path: /usr/bin/runc
    version: 'runc version spec: 1.0.2-dev'
  os: linux
  remoteSocket:
    exists: true
    path: /run/podman/podman.sock
  security:
    apparmorEnabled: false
    capabilities: CAP_NET_RAW,CAP_CHOWN,CAP_DAC_OVERRIDE,CAP_FOWNER,CAP_FSETID,CAP_KILL,CAP_NET_BIND_SERVICE,CAP_SETFCAP,CAP_SETGID,CAP_SETPCAP,CAP_SETUID,CAP_SYS_CHROOT
    rootless: false
    seccompEnabled: true
    seccompProfilePath: /usr/share/containers/seccomp.json
    selinuxEnabled: true
  serviceIsRemote: false
  slirp4netns:
    executable: /usr/bin/slirp4netns
    package: slirp4netns-1.1.8-1.module_el8.4.0+641+6116a774.x86_64
    version: |-
      slirp4netns version 1.1.8
      commit: d361001f495417b880f20329121e3aa431a8f90f
      libslirp: 4.3.1
      SLIRP_CONFIG_VERSION_MAX: 3
      libseccomp: 2.5.1
  swapFree: 1073737728
  swapTotal: 1073737728
  uptime: 1h 36m 52.78s (Approximately 0.04 days)
registries:
  search:
  - po3g231a.mirror.aliyuncs.com
  - docker.io
store:
  configFile: /etc/containers/storage.conf
  containerStore:
    number: 0
    paused: 0
    running: 0
    stopped: 0
  graphDriverName: overlay
  graphOptions:
    overlay.mountopt: nodev,metacopy=on
  graphRoot: /var/lib/containers/storage
  graphStatus:
    Backing Filesystem: xfs
    Native Overlay Diff: "false"
    Supports d_type: "true"
    Using metacopy: "true"
  imageStore:
    number: 1
  runRoot: /run/containers/storage
  volumePath: /var/lib/containers/storage/volumes
version:
  APIVersion: 3.3.1
  Built: 1636493036
  BuiltTime: Wed Nov 10 05:23:56 2021
  GitCommit: ""
  GoVersion: go1.16.7
  OsArch: linux/amd64
  Version: 3.3.1

复制代码

 

4、运行一个容器

复制代码
[root@Docker-CentOS8-12 ~]# podman run --rm -it alpine sh
Resolved "alpine" as an alias (/etc/containers/registries.conf.d/000-shortnames.conf)
Trying to pull docker.io/library/alpine:latest...
Getting image source signatures
Copying blob f56be85fc22e done  
Copying config 9ed4aefc74 done  
Writing manifest to image destination
Storing signatures
/ # 
复制代码

 

故障解决:Podman Error:OCI permission denied

[root@Docker-CentOS8-12 ~]# podman run --rm -it alpine sh
Error: container_linux.go:370: starting container process caused: error adding seccomp filter rule for syscall bdflush: permission denied: OCI permission denied

 

解决方案:更改默认的OCI运行时。某些较旧的版本runc不适用于cgroupV2,必须切换到备用OCI运行时crun

复制代码
[root@Docker-CentOS8-12 ~]# vim /usr/share/containers/containers.conf 
[root@Docker-CentOS8-12 ~]# cat /usr/share/containers/containers.conf | grep 'runtime ='
#runtime = "runc"
runtime = "crun"
[root@Docker-CentOS8-12 ~]# podman run --rm -it alpine sh
Error: default OCI runtime "crun" not found: invalid argument
[root@Docker-CentOS8-12 ~]# yum install crun -y
上次元数据过期检查:1 day, 7:33:35 前,执行于 2023年04月23日 星期日 20时48分35秒。
依赖关系解决。
================================================================================================================================================
 软件包                   架构                       版本                                                   仓库                           大小
================================================================================================================================================
安装:
 crun                     x86_64                     1.0-1.module_el8.5.0+911+f19012f9                      AppStream                     193 k
安装依赖关系:
 yajl                     x86_64                     2.1.0-10.el8                                           AppStream                      41 k

事务概要
================================================================================================================================================
安装  2 软件包

总下载:234 k
安装大小:569 k
下载软件包:
(1/2): yajl-2.1.0-10.el8.x86_64.rpm                                                                             220 kB/s |  41 kB     00:00    
(2/2): crun-1.0-1.module_el8.5.0+911+f19012f9.x86_64.rpm                                                        857 kB/s | 193 kB     00:00    
------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                            1.0 MB/s | 234 kB     00:00     
警告:/var/cache/dnf/AppStream-bf1daca1ea021975/packages/crun-1.0-1.module_el8.5.0+911+f19012f9.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID 8483c65d: NOKEY
为 AppStream 从 http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official 获取的 repo 密钥未加密
CentOS-8 - AppStream - mirrors.aliyun.com                                                                        11 kB/s | 1.6 kB     00:00    
导入 GPG 公钥 0x8483C65D:
 Userid: "CentOS (CentOS Official Signing Key) <security@centos.org>"
 指纹: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65D
 来自: http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
导入公钥成功
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
  准备中  :                                                                                                                                 1/1 
  安装    : yajl-2.1.0-10.el8.x86_64                                                                                                        1/2 
  安装    : crun-1.0-1.module_el8.5.0+911+f19012f9.x86_64                                                                                   2/2 
  运行脚本: crun-1.0-1.module_el8.5.0+911+f19012f9.x86_64                                                                                   2/2 
  验证    : crun-1.0-1.module_el8.5.0+911+f19012f9.x86_64                                                                                   1/2 
  验证    : yajl-2.1.0-10.el8.x86_64                                                                                                        2/2 

已安装:
  crun-1.0-1.module_el8.5.0+911+f19012f9.x86_64                                     yajl-2.1.0-10.el8.x86_64                                    

完毕!
[root@Docker-CentOS8-12 ~]# podman run --rm -it alpine sh
/ # 
复制代码

 

解决方案:安装升级runc版本

复制代码
[root@Docker-CentOS8-12 ~]# yum install runc -y
上次元数据过期检查:1:55:57 前,执行于 2023年04月25日 星期二 01时55分02秒。
软件包 runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64 已安装。
依赖关系解决。
================================================================================================================================================
 软件包                  架构                      版本                                                      仓库                          大小
================================================================================================================================================
升级:
 runc                    x86_64                    1.0.2-1.module_el8.5.0+911+f19012f9                       AppStream                    3.1 M

事务概要
================================================================================================================================================
升级  1 软件包

总下载:3.1 M
下载软件包:
runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64.rpm                                                             2.7 MB/s | 3.1 MB     00:01    
------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                            2.7 MB/s | 3.1 MB     00:01     
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
  准备中  :                                                                                                                                 1/1 
  升级    : runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64                                                                                 1/2 
  清理    : runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64                                                                           2/2 
  运行脚本: runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64                                                                           2/2 
  验证    : runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64                                                                                 1/2 
  验证    : runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64                                                                           2/2 

已升级:
  runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64                                                                                               

完毕!
[root@Docker-CentOS8-12 ~]# podman run --rm -it alpine sh
/ # ls
bin    dev    etc    home   lib    media  mnt    opt    proc   root   run    sbin   srv    sys    tmp    usr    var
/ # exit
复制代码

 

一键安装Docker shell脚本

Centos 7 一键在线安装

复制代码
#!/bin/bash

DOCKER_VERSION="19.03.15-3.el7"
COLOR="echo -e \\033[1;31m"
END="\033[m"

rpm -ql docker-ce &> /dev/null && $COLOR"Docker 已安装"$END && exit

$COLOR"准备安装 Docker"$END
sleep 10
yum install -y yum-utils device-mapper-persistent-data lvm2 || { $COLOR"YUM 安装失败"$END; exit; }
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo || { $COLOR"镜像源下载失败"$END; exit; }
sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
yum makecache fast
$COLOR"可安装的Docker 版本:"$END
yum list docker-ce --showduplicates
$COLOR"10s 后即将安装 docker "$DOCKER_VERSION" 版本......"$END
$COLOR"安装其他版本情使用 Ctrl+C 退出,重新选择版本"$END 
sleep 10

yum install -y docker-ce-$DOCKER_VERSION docker-ce-cli-$DOCKER_VERSION || { $COLOR"YUM安装 docker-"$DOCKER_VERSION"失败"$END; exit; }

tee > /etc/docker/daemon.json << EOF
{
  "registry-mirrors": ["https://hub-mirror.c.163.com","https://po3g231a.mirror.aliyuncs.com","https://docker.mirrors.ustc.edu.cn"]
}
EOF
systemctl daemon-reload
systemctl enable --now docker
docker --version && $COLOR"Docker-"$DOCKER_VERSION" installed Success"$END || $COLOR"Docker-"$DOCKER_VERSION" installed Faild"$END
复制代码

 

Ubuntu1804 一键在线安装

复制代码
#!/bin/bash
#
#********************************************************************
#Author:                janzen
#Date:                  2023-05-04
#FileName:             docker_install_ubu1804_online.sh
#Description:          The test script
#Copyright (C):        2023 All rights reserved
#********************************************************************
COLOR="echo -e \\033[1;31m"
END="\033[m"
DOCKER_VERSION="5:19.03.15~3-0~ubuntu-bionic"

install_docker(){
$COLOR"准备安装 Docker......"$END
sleep 10
apt update &> /dev/null
apt install -y ca-certificates curl gnupg && \
install -m 0755 -d /etc/apt/keyrings && \
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg && \
chmod a+r /etc/apt/keyrings/docker.gpg && \

echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  tee /etc/apt/sources.list.d/docker.list > /dev/null

apt update
$COLOR"Docker 可安装版本:"$END
apt-cache madison docker-ce | awk '{ print $3 }'
$COLOR"10 秒后即将安装:Docker-"$DOCKER_VERSION"版本"$END
$COLOR"安装其他版本情使用 Ctrl+C 退出,重新选择版本"$END 
sleep 10

apt install -y docker-ce=$DOCKER_VERSION docker-ce-cli=$DOCKER_VERSION
mkdir -p /etc/docker
tee /etc/docker/daemon.json << 'EOF'
{
    "registry-mirrors": ["https://hub-mirror.c.163.com","https://po3g231a.mirror.aliyuncs.com","https://docker.mirrors.ustc.edu.cn"]
}
EOF
systemctl daemon-reload
systemctl enable --now docker

docker --version && $COLOR"Docker-"$DOCKER_VERSION"安装成功"$END || $COLOR"Docker-"$DOCKER_VERSION"安装失败"$END
}

dpkg -s docker-ce &> /dev/null && { $COLOR"Docker 已安装,程序退出"$END;exit; } || install_docker
复制代码

 

#!/bin/bash
#
#********************************************************************
#Author:                janzen
#Date:                  2023-05-04
#FileName:             docker_install_ubu1804_online.sh
#Description:          The test script
#Copyright (C):        2023 All rights reserved
#********************************************************************
posted @   Janzen_Q  阅读(205)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示