参考文章:

https://docs.docker.com/install/linux/docker-ce/centos/

https://www.runoob.com/docker/centos-docker-install.html

卸载旧版本

$ sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

Modular dependency problems:

 Problem 1: conflicting requests
  - nothing provides module(perl:5.26) needed by module perl-DBD-SQLite:1.58:8010020191114033549:073fa5fe-0.x86_64
 Problem 2: conflicting requests
  - nothing provides module(perl:5.26) needed by module perl-DBI:1.641:8010020191113222731:16b3ab4d-0.x86_64
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!

设置仓库

sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2
Last metadata expiration check: 9:34:44 ago on Sun 05 Apr 2020 07:20:18 AM CST.
Package yum-utils-4.0.8-3.el8.noarch is already installed.
Package device-mapper-persistent-data-0.8.5-2.el8.x86_64 is already installed.
Package lvm2-8:2.03.05-5.el8.0.1.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!

 

sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
CentOS-8 - AppStream                                                                                                                                   2.7 kB/s | 4.3 kB     00:01    
CentOS-8 - Base                                                                                                                                        2.4 kB/s | 3.8 kB     00:01    
CentOS-8 - Extras                                                                                                                                      1.5 kB/s | 1.5 kB     00:01    
Docker CE Stable - x86_64                                                                                                                              4.4 kB/s | 3.5 kB     00:00    
Error: 
 Problem: package docker-ce-3:19.03.8-3.el7.x86_64 requires containerd.io >= 1.2.2-3, but none of the providers can be installed
  - cannot install the best candidate for the job
  - package containerd.io-1.2.10-3.2.el7.x86_64 is excluded
  - package containerd.io-1.2.13-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.2-3.3.el7.x86_64 is excluded
  - package containerd.io-1.2.2-3.el7.x86_64 is excluded
  - package containerd.io-1.2.4-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.5-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.6-3.3.el7.x86_64 is excluded
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)

解决方式:

列出并排序您存储库中可用的版本。此示例按版本号(从高到低)对结果进行排序。

yum list docker-ce --showduplicates | sort -r
Last metadata expiration check: 0:00:14 ago on Sun 05 Apr 2020 04:55:32 PM CST.
docker-ce.x86_64            3:19.03.8-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.7-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.6-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.5-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.4-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.3-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.2-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.1-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.0-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.9-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.8-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.7-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.6-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.5-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.4-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.3-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.2-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.1-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.0-3.el7                     docker-ce-stable
docker-ce.x86_64            18.06.3.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.06.2.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.06.1.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.06.0.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.03.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            18.03.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.12.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.12.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.09.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.09.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.2.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.3.ce-1.el7                    docker-ce-stable
docker-ce.x86_64            17.03.2.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.0.ce-1.el7.centos             docker-ce-stable
Available Packages

2、通过其完整的软件包名称安装特定版本,该软件包名称是软件包名称(docker-ce)加上版本字符串(第二列),从第一个冒号(:)一直到第一个连字符,并用连字符(-)分隔。例如:19.03.8

sudo yum install docker-ce-19.03.8 docker-ce-cli-19.03.8 containerd.io
Last metadata expiration check: 0:03:31 ago on Sun 05 Apr 2020 04:55:32 PM CST.
Error: 
 Problem: package docker-ce-3:19.03.8-3.el7.x86_64 requires containerd.io >= 1.2.2-3, but none of the providers can be installed
  - conflicting requests
  - package containerd.io-1.2.10-3.2.el7.x86_64 is excluded
  - package containerd.io-1.2.13-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.2-3.3.el7.x86_64 is excluded
  - package containerd.io-1.2.2-3.el7.x86_64 is excluded
  - package containerd.io-1.2.4-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.5-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.6-3.3.el7.x86_64 is excluded
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)

呵呵,又是新问题。。。。。

看上面的内容,说的是containerd.io >= 1.2.2-3 ,意思就是 containerd.io 的版本必须大于等于 1.2.2-3

要么就降低docker 的版本,要么就更新 containerd.io 的版本。

https://download.docker.com/linux/centos/7/x86_64/edge/Packages/ 这里去看看最新版本的dontainerd.io 

我这儿选最新的一个版本 下载。

wget https://download.docker.com/linux/centos/7/x86_64/edge/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm
--2020-04-05 17:01:57--  https://download.docker.com/linux/centos/7/x86_64/edge/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm
Resolving download.docker.com (download.docker.com)... 13.32.53.78, 13.32.53.12, 13.32.53.119, ...
Connecting to download.docker.com (download.docker.com)|13.32.53.78|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 27119348 (26M) [application/x-redhat-package-manager]
Saving to: ‘containerd.io-1.2.6-3.3.el7.x86_64.rpm’

containerd.io-1.2.6-3.3.el7.x86_64.rpm        100%[================================================================================================>]  25.86M  2.21MB/s    in 15s     

2020-04-05 17:02:13 (1.71 MB/s) - ‘containerd.io-1.2.6-3.3.el7.x86_64.rpm’ saved [27119348/27119348]

安装

yum install -y containerd.io-1.2.6-3.3.el7.x86_64.rpm
Last metadata expiration check: 0:07:06 ago on Sun 05 Apr 2020 04:55:32 PM CST.
Dependencies resolved.
=======================================================================================================================================================================================
 Package                                       Architecture                           Version                                       Repository                                    Size
=======================================================================================================================================================================================
Installing:
 containerd.io                                 x86_64                                 1.2.6-3.3.el7                                 @commandline                                  26 M
     replacing  runc.x86_64 1.0.0-60.rc8.module_el8.1.0+237+63e26edc

Transaction Summary
=======================================================================================================================================================================================
Install  1 Package

Total size: 26 M
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                               1/1 
  Installing       : containerd.io-1.2.6-3.3.el7.x86_64                                                                                                                            1/2 
  Running scriptlet: containerd.io-1.2.6-3.3.el7.x86_64                                                                                                                            1/2 
  Obsoleting       : runc-1.0.0-60.rc8.module_el8.1.0+237+63e26edc.x86_64                                                                                                          2/2 
  Running scriptlet: runc-1.0.0-60.rc8.module_el8.1.0+237+63e26edc.x86_64                                                                                                          2/2 
  Verifying        : containerd.io-1.2.6-3.3.el7.x86_64                                                                                                                            1/2 
  Verifying        : runc-1.0.0-60.rc8.module_el8.1.0+237+63e26edc.x86_64                                                                                                          2/2 

Installed:
  containerd.io-1.2.6-3.3.el7.x86_64                                                                                                                                                   

Complete!

我们在回去安装 docker

 sudo yum install docker-ce-19.03.8 docker-ce-cli-19.03.8 containerd.io
Last metadata expiration check: 0:07:52 ago on Sun 05 Apr 2020 04:55:32 PM CST.
Package containerd.io-1.2.6-3.3.el7.x86_64 is already installed.
Dependencies resolved.
=======================================================================================================================================================================================
 Package                                     Architecture                         Version                                         Repository                                      Size
=======================================================================================================================================================================================
Installing:
 docker-ce                                   x86_64                               3:19.03.8-3.el7                                 docker-ce-stable                                25 M
 docker-ce-cli                               x86_64                               1:19.03.8-3.el7                                 docker-ce-stable                                40 M
Installing dependencies:
 libcgroup                                   x86_64                               0.41-19.el8                                     BaseOS                                          70 k

Transaction Summary
=======================================================================================================================================================================================
Install  3 Packages

Total download size: 64 M
Installed size: 273 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): libcgroup-0.41-19.el8.x86_64.rpm                                                                                                                171 kB/s |  70 kB     00:00    
(2/3): docker-ce-cli-19.03.8-3.el7.x86_64.rpm                                                                                                          2.8 MB/s |  40 MB     00:14    
(3/3): docker-ce-19.03.8-3.el7.x86_64.rpm                                                                                                               86 kB/s |  25 MB     04:52    
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                  224 kB/s |  64 MB     04:52     
warning: /var/cache/dnf/docker-ce-stable-091d8a9c23201250/packages/docker-ce-19.03.8-3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
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 9F35
 From       : 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
The downloaded packages were saved in cache until the next successful transaction.
You can remove cached packages by executing 'dnf clean packages'.
Error: Transaction check error:
  file /usr/share/man/man1/docker-attach.1.gz from install of docker-ce-cli-1:19.03.8-3.el7.x86_64 conflicts with file from package podman-manpages-1.4.2-5.module_el8.1.0+237+63e26edc.noarch
  file /usr/share/man/man1/docker-build.1.gz from install of docker-ce-cli-1:19.03.8-3.el7.x86_64 conflicts with file from package podman-manpages-1.4.2-5.module_el8.1.0+237+63e26edc.noarch
  file /usr/share/man/man1/docker-commit.1.gz from install of docker-ce-cli-1:19.03.8-3.el7.x86_64 conflicts with file from package podman-manpages-1.4.2-5.module_el8.1.0+237+63e26edc.noarch

有一个新问题

根据提示 执行命令

dnf clean packages
3 files removed

在升级下dnf

sudo dnf update
Last metadata expiration check: 0:25:16 ago on Sun 05 Apr 2020 05:58:03 PM CST.
Dependencies resolved.
=======================================================================================================================================================================================
 Package                                                 Architecture             Version                                                            Repository                   Size
=======================================================================================================================================================================================
Installing:

....................更新内容.................
systemd-udev-239-18.el8_1.4.x86_64                                                        tuned-2.12.0-3.el8_1.1.noarch                                                              
  yum-4.2.7-7.el8_1.noarch                                                                 

Installed:
  kernel-4.18.0-147.5.1.el8_1.x86_64        kernel-core-4.18.0-147.5.1.el8_1.x86_64  kernel-modules-4.18.0-147.5.1.el8_1.x86_64  conmon-2:2.0.6-1.module_el8.1.0+272+3e64ee36.x86_64 
  grub2-tools-efi-1:2.02-78.el8_1.1.x86_64 

Complete!

再次安装docker

sudo yum install docker-ce docker-ce-cli containerd.io
Last metadata expiration check: 0:33:56 ago on Sun 05 Apr 2020 05:58:03 PM CST.
Package containerd.io-1.2.6-3.3.el7.x86_64 is already installed.
Dependencies resolved.
=======================================================================================================================================================================================
 Package                                     Architecture                         Version                                         Repository                                      Size
=======================================================================================================================================================================================
Installing:
 docker-ce                                   x86_64                               3:19.03.8-3.el7                                 docker-ce-stable                                25 M
 docker-ce-cli                               x86_64                               1:19.03.8-3.el7                                 docker-ce-stable                                40 M
Installing dependencies:
 libcgroup                                   x86_64                               0.41-19.el8                                     BaseOS                                          70 k

Transaction Summary
=======================================================================================================================================================================================
Install  3 Packages

Total download size: 64 M
Installed size: 273 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): libcgroup-0.41-19.el8.x86_64.rpm                                                                                                                185 kB/s |  70 kB     00:00    
(2/3): docker-ce-cli-19.03.8-3.el7.x86_64.rpm                                                                                                          3.1 MB/s |  40 MB     00:12    
[MIRROR] docker-ce-19.03.8-3.el7.x86_64.rpm: Curl error (28): Timeout was reached for https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-19.03.8-3.el7.x86_64.rpm [Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds]
(3/3): docker-ce-19.03.8-3.el7.x86_64.rpm                                                                                                               24 kB/s |  25 MB     17:36    
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                   62 kB/s |  64 MB     17:36     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                               1/1 
  Installing       : docker-ce-cli-1:19.03.8-3.el7.x86_64                                                                                                                          1/3 
  Running scriptlet: docker-ce-cli-1:19.03.8-3.el7.x86_64                                                                                                                          1/3 
  Running scriptlet: libcgroup-0.41-19.el8.x86_64                                                                                                                                  2/3 
  Installing       : libcgroup-0.41-19.el8.x86_64                                                                                                                                  2/3 
  Running scriptlet: libcgroup-0.41-19.el8.x86_64                                                                                                                                  2/3 
  Installing       : docker-ce-3:19.03.8-3.el7.x86_64                                                                                                                              3/3 
  Running scriptlet: docker-ce-3:19.03.8-3.el7.x86_64                                                                                                                              3/3 
  Verifying        : libcgroup-0.41-19.el8.x86_64                                                                                                                                  1/3 
  Verifying        : docker-ce-3:19.03.8-3.el7.x86_64                                                                                                                              2/3 
  Verifying        : docker-ce-cli-1:19.03.8-3.el7.x86_64                                                                                                                          3/3 

Installed:
  docker-ce-3:19.03.8-3.el7.x86_64                            docker-ce-cli-1:19.03.8-3.el7.x86_64                            libcgroup-0.41-19.el8.x86_64                           

Complete!

查看docker版本

docker -v
Docker version 19.03.8, build afacb8b

启动docker 服务

sudo systemctl start docker

运行一个hello-wrold 容器

docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete 
Digest: sha256:f9dfddf63636d84ef479d645ab5885156ae030f611a56f3a7ac7f2fdd86d7e4e
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

[root@localhost xiajun]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              fce289e99eb9        15 months ago       1.84kB
[root@localhost xiajun]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@localhost xiajun]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
8032055c0c83        hello-world         "/hello"            4 minutes ago       Exited (0) 4 minutes ago                       clever_buck

 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐