2、docker安装

1、安装前提

CentOS Docker 安装
Docker支持以下的CentOS版本:
CentOS 7 (64-bit)
CentOS 6.5 (64-bit) 或更高的版本

前提条件
目前,CentOS 仅发行版本中的内核支持 Docker。
Docker 运行在 CentOS 7 上,要求系统为64位、系统内核版本为 3.10 以上。
Docker 运行在 CentOS-6.5 或更高的版本的 CentOS 上,要求系统为64位、系统内核版本为 2.6.32-431 或者更高版本。

查看自己的内核
uname命令用于打印当前系统相关信息(内核版本号、硬件架构、主机名称和操作系统类型等)。

查看已安装的CentOS版本信息(CentOS6.8有,CentOS7无该命令)

2、安装步骤

2.1 CentOS6.8

1)yum install -y epel-release

Docker使用EPEL发布,RHEL系的OS首先要确保已经持有EPEL仓库,否则先检查OS的版本,然后安装相应的EPEL包。

2)yum install docker-io

3)/etc/sysconfig/docker

4)启动docker后台服务

service docker start

5)docker version验证

2.2 CentOS8.0

最新的安装地址(CentOS8)
https://docs.docker.com/engine/install/centos/

sudo yum install -y yum-utils
[root@localhost ~]# sudo yum install -y yum-utils
CentOS-8 - AppStream                                                                                                                   1.0 MB/s | 6.6 MB     00:06    
CentOS-8 - Base                                                                                                                        588 kB/s | 5.0 MB     00:08    
CentOS-8 - Extras                                                                                                                      5.0 kB/s | 4.9 kB     00:00    
依赖关系解决。
=======================================================================================================================================================================
 软件包                                   架构                                  版本                                       仓库                                   大小
=======================================================================================================================================================================
安装:
 yum-utils                                noarch                                4.0.8-3.el8                                BaseOS                                 64 k

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

总下载:64 k
安装大小:19 k
下载软件包:
yum-utils-4.0.8-3.el8.noarch.rpm                                                                                                       145 kB/s |  64 kB     00:00    
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                                                    54 kB/s |  64 kB     00:01     
警告:/var/cache/dnf/BaseOS-929b586ef1f72f69/packages/yum-utils-4.0.8-3.el8.noarch.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID 8483c65d: NOKEY
CentOS-8 - Base                                                                                                                        142 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
 来自: /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
导入公钥成功
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
  准备中  :                                                                                                                                                        1/1 
  安装    : yum-utils-4.0.8-3.el8.noarch                                                                                                                           1/1 
  运行脚本: yum-utils-4.0.8-3.el8.noarch                                                                                                                           1/1 
  验证    : yum-utils-4.0.8-3.el8.noarch                                                                                                                           1/1 

已安装:
  yum-utils-4.0.8-3.el8.noarch                                                                                                                                         

完毕!

sudo yum-config-manager
[root@localhost ~]# sudo yum-config-manager \
>     --add-repo \
>     https://download.docker.com/linux/centos/docker-ce.repo
添加仓库自:https://download.docker.com/linux/centos/docker-ce.repo
[root@localhost ~]# 

切换阿里云镜像

[root@localhost ~]# sudo yum-config-manager \
>     --add-repo \
>     https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

1、CentOS8 INSTALL DOCKER ENGINE

Install the latest version of Docker Engine and containerd, or go to the next step to install a specific version:

1.1安装遇到错误问题1: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

[root@localhost ~]# sudo yum install docker-ce docker-ce-cli containerd.io
CentOS-8 - AppStream                                                                                                                   5.7 kB/s | 4.3 kB     00:00    
CentOS-8 - Base                                                                                                                        4.8 kB/s | 3.8 kB     00:00    
CentOS-8 - Extras                                                                                                                      1.4 kB/s | 1.5 kB     00:01    
Docker CE Stable - x86_64                                                                                                              8.2 kB/s |  22 kB     00:02    
错误:
 问题: 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
###问题分析
centos8默认使用podman代替docker,所以需要containerd.io,那我们就安装一下就好了
安装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

[root@localhost ~]# yum install https://download.docker.com/linux/fedora/30/x86_64/stable/Packages/containerd.io-1.2.10-3.2.fc30.x86_64.rpm
上次元数据过期检查:0:24:10 前,执行于 2020年04月09日 星期四 02时44分09秒。
containerd.io-1.2.10-3.2.fc30.x86_64.rpm                                                                                                20 kB/s |  23 MB     19:18    
依赖关系解决。
=======================================================================================================================================================================
 软件包                                   架构                              版本                                         仓库                                     大小
=======================================================================================================================================================================
安装:
 containerd.io                            x86_64                            1.2.10-3.2.fc30                              @commandline                             23 M
     替换  runc.x86_64 1.0.0-60.rc8.module_el8.1.0+237+63e26edc

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

总计:23 M
确定吗?[y/N]: y
下载软件包:
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
  准备中  :                                                                                                                                                        1/1 
  安装    : containerd.io-1.2.10-3.2.fc30.x86_64                                                                                                                   1/2 
  运行脚本: containerd.io-1.2.10-3.2.fc30.x86_64                                                                                                                   1/2 
  废弃    : runc-1.0.0-60.rc8.module_el8.1.0+237+63e26edc.x86_64                                                                                                   2/2 
  运行脚本: runc-1.0.0-60.rc8.module_el8.1.0+237+63e26edc.x86_64                                                                                                   2/2 
  验证    : containerd.io-1.2.10-3.2.fc30.x86_64                                                                                                                   1/2 
  验证    : runc-1.0.0-60.rc8.module_el8.1.0+237+63e26edc.x86_64                                                                                                   2/2 

已安装:
  containerd.io-1.2.10-3.2.fc30.x86_64                                                                                                                                 

完毕!

1.2 安装遇到错误问题2

安装过程中出现 错误:事务检查错误:

卸载podman

错误:事务检查错误:
  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

docker与podman冲突,podman也是容器技术,貌似比docker先进,先卸载。

[root@localhost ~]# sudo yum install docker-ce docker-ce-cli containerd.io
上次元数据过期检查:0:01:01 前,执行于 2020年04月09日 星期四 03时50分39秒。
软件包 containerd.io-1.2.10-3.2.fc30.x86_64 已安装。
依赖关系解决。
=======================================================================================================================================================================
 软件包                                  架构                             版本                                        仓库                                        大小
=======================================================================================================================================================================
安装:
 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
安装依赖关系:
 libcgroup                               x86_64                           0.41-19.el8                                 BaseOS                                      70 k

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

总下载:64 M
安装大小:273 M
确定吗?[y/N]: y
下载软件包:
(1/3): libcgroup-0.41-19.el8.x86_64.rpm                                                                                                 62 kB/s |  70 kB     00:01    
(2/3): docker-ce-19.03.8-3.el7.x86_64.rpm                                                                                              1.6 MB/s |  25 MB     00:15    
(3/3): docker-ce-cli-19.03.8-3.el7.x86_64.rpm                                                                                          2.0 MB/s |  40 MB     00:19    
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                                                   3.2 MB/s |  64 MB     00:20     
警告:/var/cache/dnf/docker-ce-stable-3e5647bf4960c796/packages/docker-ce-19.03.8-3.el7.x86_64.rpm: 头V4 RSA/SHA512 Signature, 密钥 ID 621e9f35: NOKEY
Docker CE Stable - x86_64                                                                                                               16 kB/s | 1.6 kB     00:00    
导入 GPG 公钥 0x621E9F35:
 Userid: "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
确定吗?[y/N]: y
导入公钥成功
运行事务检查
事务检查成功。
运行事务测试
下载的软件包保存在缓存中,直到下次成功执行事务。
您可以通过执行 'dnf clean packages' 删除软件包缓存。
错误:事务检查错误:
  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
  file /usr/share/man/man1/docker-container-prune.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-container.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-cp.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-create.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

............................................................................................





[root@dev1 docker-19.03.8-rpm]# rpm -q podman
podman-1.4.2-5.module_el8.1.0+237+63e26edc.x86_64

[root@dev1 docker-19.03.8-rpm]# yum remove podman
[root@localhost ~]# yum remove podman
模块依赖问题

 问题 1: conflicting requests
  - nothing provides module(perl:5.26) needed by module perl-DBD-SQLite:1.58:8010020191114033549:073fa5fe-0.x86_64
 问题 2: conflicting requests
  - nothing provides module(perl:5.26) needed by module perl-DBI:1.641:8010020191113222731:16b3ab4d-0.x86_64
依赖关系解决。
=======================================================================================================================================================================
 软件包                             架构                     版本                                                                   仓库                          大小
=======================================================================================================================================================================
移除:
 podman                             x86_64                   1.4.2-5.module_el8.1.0+237+63e26edc                                    @AppStream                    51 M
移除依赖的软件包:
 cockpit-podman                     noarch                   4-1.module_el8.1.0+237+63e26edc                                        @AppStream                   5.1 M
清除未被使用的依赖关系:
 libvarlink                         x86_64                   18-3.el8                                                               @anaconda                    129 k
 oci-systemd-hook                   x86_64                   1:0.1.15-2.git2d0b8a3.module_el8.1.0+237+63e26edc                      @AppStream                    74 k
 podman-manpages                    noarch                   1.4.2-5.module_el8.1.0+237+63e26edc                                    @AppStream                   134 k

事务概要
=======================================================================================================================================================================
移除  5 软件包

将会释放空间:56 M
确定吗?[y/N]: y
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
  准备中  :                                                                                                                                                        1/1 
  运行脚本: cockpit-podman-4-1.module_el8.1.0+237+63e26edc.noarch                                                                                                  1/1 
  删除    : cockpit-podman-4-1.module_el8.1.0+237+63e26edc.noarch                                                                                                  1/5 
  删除    : podman-1.4.2-5.module_el8.1.0+237+63e26edc.x86_64                                                                                                      2/5 
  运行脚本: podman-1.4.2-5.module_el8.1.0+237+63e26edc.x86_64                                                                                                      2/5 
  删除    : podman-manpages-1.4.2-5.module_el8.1.0+237+63e26edc.noarch                                                                                             3/5 
  删除    : oci-systemd-hook-1:0.1.15-2.git2d0b8a3.module_el8.1.0+237+63e26edc.x86_64                                                                              4/5 
  删除    : libvarlink-18-3.el8.x86_64                                                                                                                             5/5 
  运行脚本: libvarlink-18-3.el8.x86_64                                                                                                                             5/5 
  验证    : cockpit-podman-4-1.module_el8.1.0+237+63e26edc.noarch                                                                                                  1/5 
  验证    : libvarlink-18-3.el8.x86_64                                                                                                                             2/5 
  验证    : oci-systemd-hook-1:0.1.15-2.git2d0b8a3.module_el8.1.0+237+63e26edc.x86_64                                                                              3/5 
  验证    : podman-1.4.2-5.module_el8.1.0+237+63e26edc.x86_64                                                                                                      4/5 
  验证    : podman-manpages-1.4.2-5.module_el8.1.0+237+63e26edc.noarch                                                                                             5/5 

已移除:
  podman-1.4.2-5.module_el8.1.0+237+63e26edc.x86_64                           cockpit-podman-4-1.module_el8.1.0+237+63e26edc.noarch        libvarlink-18-3.el8.x86_64  
  oci-systemd-hook-1:0.1.15-2.git2d0b8a3.module_el8.1.0+237+63e26edc.x86_64   podman-manpages-1.4.2-5.module_el8.1.0+237+63e26edc.noarch  

完毕!
[root@localhost ~]# 

1.3 正确的完整安装过程

[root@localhost ~]# sudo yum install docker-ce docker-ce-cli containerd.io
上次元数据过期检查:0:08:45 前,执行于 2020年04月09日 星期四 03时50分39秒。
软件包 containerd.io-1.2.10-3.2.fc30.x86_64 已安装。
依赖关系解决。
=======================================================================================================================================================================
 软件包                                  架构                             版本                                        仓库                                        大小
=======================================================================================================================================================================
安装:
 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
安装依赖关系:
 libcgroup                               x86_64                           0.41-19.el8                                 BaseOS                                      70 k

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

总计:64 M
安装大小:273 M
确定吗?[y/N]: y
下载软件包:
[SKIPPED] libcgroup-0.41-19.el8.x86_64.rpm: Already downloaded                                                                                                        
[SKIPPED] docker-ce-19.03.8-3.el7.x86_64.rpm: Already downloaded                                                                                                      
[SKIPPED] docker-ce-cli-19.03.8-3.el7.x86_64.rpm: Already downloaded                                                                                                  
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                                                   6.3 GB/s |  64 MB     00:00     
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
  准备中  :                                                                                                                                                        1/1 
  安装    : docker-ce-cli-1:19.03.8-3.el7.x86_64                                                                                                                   1/3 
  运行脚本: docker-ce-cli-1:19.03.8-3.el7.x86_64                                                                                                                   1/3 
  运行脚本: libcgroup-0.41-19.el8.x86_64                                                                                                                           2/3 
  安装    : libcgroup-0.41-19.el8.x86_64                                                                                                                           2/3 
  运行脚本: libcgroup-0.41-19.el8.x86_64                                                                                                                           2/3 
  安装    : docker-ce-3:19.03.8-3.el7.x86_64                                                                                                                       3/3 
  运行脚本: docker-ce-3:19.03.8-3.el7.x86_64                                                                                                                       3/3 
  验证    : libcgroup-0.41-19.el8.x86_64                                                                                                                           1/3 
  验证    : docker-ce-3:19.03.8-3.el7.x86_64                                                                                                                       2/3 
  验证    : docker-ce-cli-1:19.03.8-3.el7.x86_64                                                                                                                   3/3 

已安装:
  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                      

完毕!

启动Docker

[root@localhost ~]# 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
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?


[root@localhost ~]# systemctl start docker
[root@localhost ~]# 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.10
  GitCommit:        b34a5c8af56e510852c35414db4c1f4fa6172339
 runc:
  Version:          1.0.0-rc8+dev
  GitCommit:        3e425f80a8c931f88e6d94a8c831b9d5aa481657
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

helloworld

[root@localhost ~]# 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 ~]# 

docker images

[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              fce289e99eb9        15 months ago       1.84kB
posted @ 2020-04-07 21:20  xidianzxm  阅读(712)  评论(0编辑  收藏  举报