CentOS上安装Docker

Docker centos 官方安装教程:docker for centos

 

1. 卸载旧的

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

 

2.设置存储库

安装yum-utils软件包(提供yum-config-manager 实用程序)并设置稳定的存储库。

$ sudo yum install -y yum-utils

$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

3.启用测试

$ sudo yum-config-manager --enable docker-ce-nightly

 

4.开始安装:

$ sudo yum install docker-ce docker-ce-cli containerd.io
  • containerd.io - daemon to interface with the OS API (in this case, LXC - Linux Containers), essentially decouples Docker from the OS, also provides container services for non-Docker container managers

  • docker-ce - Docker daemon, this is the part that does all the management work, requires the other two on Linux

  • docker-ce-cli - CLI tools to control the daemon, you can install them on their own if you want to control a remote Docker daemon

这个地方遇到了错误

 

提示需要 containerd.io并且版本大于1.2.2-3,但是找不到,下面手动安装

yum install https://download.docker.com/linux/fedora/30/x86_64/stable/Packages/containerd.io-1.2.6-3.3.fc30.x86_64.rpm
# yum install https://download.docker.com/linux/fedora/30/x86_64/stable/Packages/containerd.io

-1.2.6-3.3.fc
c30.x86_64.rpm
Last metadata expiration check: 0:09:53 ago on Thu 30 Apr 2020 11:49:45 AM CST.
containerd.io-1.2.6-3.3.fc30.x86_64.rpm      [===                                     ] ---  B/s |   0  B     --:-- ETA
containerd.io-1.2.6-3.3.fc30.x86_64.rpm      [===                                     ] ---  B/s |   0  B     --:-- ETA
containerd.io-1.2.6-3.3.fc30.x86_64.rpm   0% [                                        ] ---  B/s |   0  B     --:-- ETA
containerd.io-1.2.6-3.3.fc30.x86_64.rpm   0% [                                        ] 409 kB/s | 148 kB     00:53 ETA
containerd.io-1.2.6-3.3.fc30.x86_64.rpm   3% [=                                       ] 479 kB/s | 676 kB     00:44 ETA
containerd.io-1.2.6-3.3.fc30.x86_64.rpm   8% [===                                     ] 675 kB/s | 1.8 MB     00:29 ETA
containerd.io-1.2.6-3.3.fc30.x86_64.rpm  15% [======                                  ] 955 kB/s | 3.3 MB     00:19 ETA
containerd.io-1.2.6-3.3.fc30.x86_64.rpm  24% [=========-                              ] 1.2 MB/s | 5.3 MB     00:12 ETA
containerd.io-1.2.6-3.3.fc30.x86_64.rpm  31% [============-                           ] 1.4 MB/s | 6.8 MB     00:10 ETA
containerd.io-1.2.6-3.3.fc30.x86_64.rpm  46% [==================-                     ] 2.0 MB/s | 9.9 MB     00:05 ETA
containerd.io-1.2.6-3.3.fc30.x86_64.rpm  49% [===================-                    ] 2.0 MB/s |  11 MB     00:05 ETA
containerd.io-1.2.6-3.3.fc30.x86_64.rpm  64% [=========================-              ] 2.5 MB/s |  14 MB     00:02 ETA
containerd.io-1.2.6-3.3.fc30.x86_64.rpm  70% [============================            ] 2.6 MB/s |  15 MB     00:02 ETA
containerd.io-1.2.6-3.3.fc30.x86_64.rpm  77% [==============================-         ] 2.7 MB/s |  17 MB     00:01 ETA
containerd.io-1.2.6-3.3.fc30.x86_64.rpm  91% [====================================-   ] 3.1 MB/s |  20 MB     00:00 ETA
containerd.io-1.2.6-3.3.fc30.x86_64.rpm  95% [======================================  ] 3.0 MB/s |  20 MB     00:00 ETA
containerd.io-1.2.6-3.3.fc30.x86_64.rpm                                                 3.8 MB/s |  21 MB     00:05
Dependencies resolved.
========================================================================================================================

 Package                   Architecture   Version                                            Repository            Size
========================================================================================================================

Installing:
 containerd.io             x86_64         1.2.6-3.3.fc30                                     @commandline          21 M
Installing dependencies:
 container-selinux         noarch         2:2.124.0-1.module_el8.1.0+298+41f9343a            AppStream             47 k
Enabling module streams:
 container-tools                          rhel8

Transaction Summary
========================================================================================================================

Install  2 Packages

Total size: 21 M
Total download size: 47 k
Installed size: 84 M
Is this ok [y/N]: y
Downloading Packages:
container-selinux-2.124.0-1.module_el8.1  0% [                                        ] ---  B/s |   0  B     --:-- ETA
container-selinux-2.124.0-1.module_el8.1.0+298+41f9343a.noarch.rpm                      1.1 MB/s |  47 kB     00:00
------------------------------------------------------------------------------------------------------------------------

Total                                                                                   1.1 MB/s |  47 kB     00:00...........
Installed:
  containerd.io-1.2.6-3.3.fc30.x86_64          container-selinux-2:2.124.0-1.module_el8.1.0+298+41f9343a.noarch


Complete!

 安装完成下一步继续安装Docker

 sudo yum install docker-ce docker-ce-cli

 其实这3个可以一个个单独安装

yum install docker-ce
# yum install docker-ce
Last metadata expiration check: 0:12:39 ago on Thu 30 Apr 2020 11:49:45 AM CST.
Dependencies resolved.
==================================================================================================================

 Package                     Architecture         Version                          Repository
==================================================================================================================

Installing:
 docker-ce                   x86_64               3:19.03.8-3.el7                  docker-ce-stable
Installing dependencies:
 libcgroup                   x86_64               0.41-19.el8                      BaseOS
 docker-ce-cli               x86_64               1:19.03.8-3.el7                  docker-ce-stable

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   0% [                                        ] ---  B/s |   0  B     --:-
(1/3): libcgroup-0.41-19.el8.x86_64.rpm                                                 640 kB/s |  70 kB     00:0
(2-3/3): docker-ce-cli-19.03.8-3.el7.x86  0% [                                        ] 640 kB/s |  70 kB     01:4
(2-3/3): docker-ce-cli-19.03.8-3.el7.x86  0% [                                        ] 640 kB/s |  70 kB     01:4
(2-3/3): docker-ce-cli-19.03.8-3.el7.x86  0% [                                        ] 623 kB/s | 180 kB     01:4
(2-3/3): docker-ce-19.03.8-3.el7.x86_64.  2% [-                                       ] 864 kB/s | 1.5 MB     01:1
(2-3/3): docker-ce-19.03.8-3.el7.x86_64.  5% [==                                      ] 1.1 MB/s | 3.2 MB     00:5
(2-3/3): docker-ce-19.03.8-3.el7.x86_64. 16% [======-                                 ] 2.5 MB/s |  11 MB     00:2
(2-3/3): docker-ce-cli-19.03.8-3.el7.x86 21% [========-                               ] 3.0 MB/s |  14 MB     00:1
(2-3/3): docker-ce-cli-19.03.8-3.el7.x86 29% [===========-                            ] 3.8 MB/s |  19 MB     00:1
(2-3/3): docker-ce-cli-19.03.8-3.el7.x86 36% [==============-                         ] 4.5 MB/s |  24 MB     00:0
(2-3/3): docker-ce-19.03.8-3.el7.x86_64. 39% [===============-                        ] 4.6 MB/s |  25 MB     00:0
(2-3/3): docker-ce-19.03.8-3.el7.x86_64. 53% [=====================                   ] 6.1 MB/s |  34 MB     00:0
(2-3/3): docker-ce-19.03.8-3.el7.x86_64. 56% [======================-                 ] 6.2 MB/s |  36 MB     00:0
(2-3/3): docker-ce-cli-19.03.8-3.el7.x86 65% [==========================              ] 6.9 MB/s |  42 MB     00:0
(2-3/3): docker-ce-cli-19.03.8-3.el7.x86 71% [============================-           ] 7.3 MB/s |  46 MB     00:0
(2-3/3): docker-ce-cli-19.03.8-3.el7.x86 81% [================================        ] 8.0 MB/s |  52 MB     00:0
(2/3): docker-ce-19.03.8-3.el7.x86_64.rpm                                               5.4 MB/s |  25 MB     00:0
(3/3): docker-ce-cli-19.03.8-3.el7.x86_6 82% [=================================       ] 8.0 MB/s |  53 MB     00:0
(3/3): docker-ce-cli-19.03.8-3.el7.x86_6 85% [==================================      ] 7.8 MB/s |  55 MB     00:0
(3/3): docker-ce-cli-19.03.8-3.el7.x86_6 92% [====================================-   ] 8.2 MB/s |  59 MB     00:0
(3/3): docker-ce-cli-19.03.8-3.el7.x86_6 94% [=====================================-  ] 7.8 MB/s |  60 MB     00:0
(3/3): docker-ce-cli-19.03.8-3.el7.x86_64.rpm                                           6.6 MB/s |  40 MB     00:0
------------------------------------------------------------------------------------------------------------------

Total                                                                                    11 MB/s |  64 MB     00:0...............................................省略

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

Complete!

OK 安装完成.

如上所示,注意要先安装依赖选项再安装会保险些.

 

 

总结:CentOS8 安装Docker六部曲

1.删除旧版本 

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

 

2.安装yum工具并设置存储库 

$ sudo yum install -y yum-utils

$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

  

3.安装containerd.io(自动安装找不到路径,这里强制设置安装下载地址)

yum install https://download.docker.com/linux/fedora/30/x86_64/stable/Packages/containerd.io-1.2.6-3.3.fc30.x86_64.rpm

4.安装Docker CE 和Docker ce-cli

 sudo yum install docker-ce docker-ce-cli

 

5.启动Docker

 sudo systemctl start docker

 

6.通过运行hello-world 映像来验证是否正确安装了Docker Engine 。

sudo docker run hello-world

 

 补充:

7.开启服务自启动

# systemctl  enable docker.service
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.

 

其它:

查看docker版本

# docker version
Client: Docker Engine - Community
 Version:           19.03.8
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        afacb8b
 Built:             Wed Mar 11 01:27:04 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.8
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.17
  Git commit:       afacb8b
  Built:            Wed Mar 11 01:25:42 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.6
  GitCommit:        894b81a4b802e4eb2a91d1ce216b8817763c29fb
 runc:
  Version:          1.0.0-rc8
  GitCommit:        425e105d5a03fabd737a126ad93d62a9eeede87f
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

 

posted @ 2020-04-30 11:55  Merray  Views(556)  Comments(0Edit  收藏  举报