CentOS8安装最新Docker教程(含离线安装方法)

一、离线安装

我已经将安装Docker所有需要rpm上传: Dcoker整合包,这样就可以离线安装Docker。

整合包安装平台:CentOS

Docker版本:19.03.12

下载解压后,进入解压后的目录,执行:

sudo rpm -Uvh *.rpm

[jeremy@cent8-02-jeremy docker]$ sudo rpm -Uvh *.rpm
[sudo] password for jeremy: 
warning: audit-3.0-0.17.20191104git1c2f876.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEY
warning: containerd.io-1.2.13-3.2.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:libsepol-2.9-1.el8               ################################# [  3%]
...
  19:container-selinux-2:2.124.0-1.mod################################# [ 59%]
  20:containerd.io-1.2.13-3.2.el7     ################################# [ 63%]
  21:docker-ce-3:19.03.12-3.el7       ################################# [ 66%]
  22:audit-3.0-0.17.20191104git1c2f876################################# [ 69%]
Cleaning up / removing...
  23:selinux-policy-targeted-3.14.1-61################################# [ 72%]
  24:audit-3.0-0.10.20180831git0047a6c################################# [ 75%]
  25:python3-libselinux-2.8-6.el8     ################################# [ 78%]
  26:selinux-policy-3.14.1-61.el8     ################################# [ 81%]
  27:policycoreutils-2.8-16.1.el8     ################################# [ 84%]
  28:libsemanage-2.8-5.el8            ################################# [ 88%]
  29:libselinux-utils-2.8-6.el8       ################################# [ 91%]
  30:libselinux-2.8-6.el8             ################################# [ 94%]
  31:libsepol-2.8-2.el8               ################################# [ 97%]
  32:audit-libs-3.0-0.10.20180831git00################################# [100%]

二、Yum源安装

2.1 添加清华源

执行:

sudo dnf config-manager --add-repo https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo

[jeremy@cent8-01-jeremy ~]$ sudo dnf config-manager --add-repo https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
[sudo] password for jeremy: 
Adding repo from: https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo

这样其实只是在清华大学开源软件镜像站下载了Docker官方仓库,这样安装软件还是很慢。替换为清华源,执行:

sudo sed -i 's+download.docker.com+mirrors.tuna.tsinghua.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo

[jeremy@cent8-01-jeremy ~]$ sudo sed -i 's+download.docker.com+mirrors.tuna.tsinghua.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo
[sudo] password for jeremy: 

2.2 安装container-selinux

执行:

sudo dnf install container-selinux

[jeremy@cent8-01-jeremy ~]$ sudo dnf install container-selinux
Last metadata expiration check: 0:15:22 ago on Sat 12 Sep 2020 01:47:31 PM CST.
Dependencies resolved.
====================================================================
 Package                  Arch   Version            Repository
                                                               Size
====================================================================
Installing:
 container-selinux        noarch 2:2.124.0-1.module_el8.2.0+305+5e198a41
                                                    AppStream  47 k
Upgrading:
 audit                    x86_64 3.0-0.17.20191104git1c2f876.el8
                                                    BaseOS    254 k
 audit-libs               x86_64 3.0-0.17.20191104git1c2f876.el8
                                                    BaseOS    116 k
 libsemanage              x86_64 2.9-2.el8          BaseOS    165 k
 policycoreutils          x86_64 2.9-9.el8          BaseOS    377 k
 selinux-policy           noarch 3.14.3-41.el8_2.5  BaseOS    614 k
 selinux-policy-targeted  noarch 3.14.3-41.el8_2.5  BaseOS     15 M
Installing dependencies:
 policycoreutils-python-utils
                          noarch 2.9-9.el8          BaseOS    251 k
 python3-audit            x86_64 3.0-0.17.20191104git1c2f876.el8
                                                    BaseOS     86 k
 python3-libsemanage      x86_64 2.9-2.el8          BaseOS    127 k
 python3-policycoreutils  noarch 2.9-9.el8          BaseOS    2.2 M
 python3-setools          x86_64 4.2.2-2.el8        BaseOS    601 k
Enabling module streams:
 container-tools                 rhel8                             

Transaction Summary
====================================================================
Install  6 Packages
Upgrade  6 Packages

Total download size: 20 M

2.3 安装Docker

执行:

sudo dnf install --repo BaseOS,docker-ce-stable docker-ce docker-ce-cli containerd.io

[jeremy@cent8-01-jeremy ~]$ sudo dnf install --repo BaseOS,docker-ce-stable docker-ce docker-ce-cli containerd.io
Last metadata expiration check: 0:34:13 ago on Sat 12 Sep 2020 01:47:31 PM CST.
Dependencies resolved.
==============================================================================================================================================================
 Package                               Arch                           Version                                  Repository                                Size
==============================================================================================================================================================
Installing:
 containerd.io                         x86_64                         1.2.13-3.2.el7                           docker-ce-stable                          25 M
 docker-ce                             x86_64                         3:19.03.12-3.el7                         docker-ce-stable                          24 M
 docker-ce-cli                         x86_64                         1:19.03.12-3.el7                         docker-ce-stable                          38 M
Installing dependencies:
 libcgroup                             x86_64                         0.41-19.el8                              BaseOS                                    70 k
 xz                                    x86_64                         5.2.4-3.el8                              BaseOS                                   153 k

Transaction Summary
==============================================================================================================================================================
Install  5 Packages

Total download size: 88 M
Installed size: 360 M

三、启动Docker

执行:

sudo systemctl start docker

[jeremy@cent8-01-jeremy ~]$ sudo systemctl start docker
[sudo] password for jeremy: 

四、运行第一个Docker镜像

执行:

sudo docker run hello-world

[jeremy@cent8-01-jeremy ~]$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete 
Digest: sha256:4cf9c47f86df71d48364001ede3a4fcd85ae80ce02ebad74156906caff5378bc
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/

五、坑

5.1 requires containerd.io >= 1.2.2-3

本来理想状态下,直接执行:

sudo dnf install docker-ce docker-ce-cli containerd.io

就可以安装完成了,结果:

[jeremy@cent8-01-jeremy ~]$ sudo dnf install docker-ce docker-ce-cli containerd.io
Last metadata expiration check: 0:01:30 ago on Sat 12 Sep 2020 01:47:31 PM CST.
Error: 
 Problem: package docker-ce-3:19.03.12-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.13-3.2.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)

这里提示:

Error: 
 Problem: package docker-ce-3:19.03.12-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.13-3.2.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)

经过我一番研究,知道了为什么会这样,但是构成的原因不是很理解,只是知道现象,可能是因为还没有适配CentOS8吧,不过知道如何解决也好。

因为container-selinux-2:2.124.0-1containerd.io之间引起的问题。

直接执行安装是,containerd.io依赖container-selinuxcontainer-selinux在AppStream仓库内,启用了该仓库就会自动过滤了containerd.io-1.2.0-3.el7之后的版本,但是docker-ce-3:19.03.12-3.el7依赖containerd.io,要求本版>= 1.2.2-3,陷入僵局。


若文章有误,或你有什么见解,欢迎留言交流指正。
原创不易,若有所帮助,欢迎点赞、收藏。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值