CentOS8下安装Docker

在安装之前,我们先了解什么是Docker

什么是Docker?

Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中,然后发布到任何流行的 Linux或Windows操作系统的机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口。

1、Docker是基于Go语言实现的云开源项目。
2、Docker的主要目标是,“Build,Ship and Run Any App,Anywhere”,也就是通过对应用组件的封装、分发、部署、运行等生命周期的管理,使用户的App(可以是一个Web应用或数据库应用等)及其运行环境能够做到“一次封装,到处运行”。

Docke能干什么?

传统虚拟技术,比如VMware,它是虚拟出一套硬件后,在其上运行一个完整操作系统,在该系统上再运行所需应用进程。【可以看出,虚拟机需要的内存大,而且配置麻烦】

而容器内的应用进程直接运行于宿主的内核,容器没有自己的内核,而且没有进行硬件模拟,因此,容器要比传统虚拟机更轻便。
每个容器之间互相隔离,每个容器有自己的文件系统,容器之间进程不会互相影响,能区分计算资源。

Docker主要的思想就是来自于集装箱,Docker采用隔离机制,对每个应用进行打包装箱,每个箱子都是互相隔离订单,可以理解为是一个个的镜像,镜像内部附带有运行环境。

容器化技术并不是模拟的一个完整的操作系统

Docker三要素

镜像(image):docker镜像就好比一个模板,可以通过这个模板来创建容器服务

容器(container): docker利用容器技术,独立运行一个或者一组应用,通过镜像来创建

**仓库(repository):**仓库,顾名思义,就是存放镜像的地方,其中,仓库分公有仓库和私有仓库

CentOS8安装Docker

首先查看内核

  • uname - r
    uname 用于打印当前系统相关信息,如内核版本号、硬件架构、主机名称和操作系统类型等】
4.18.0-80.el8.x86_64

查看内核信息

  • cat /etc/os-release
NAME="CentOS Linux"
VERSION="8 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="CentOS Linux 8 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:8"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-8"
CENTOS_MANTISBT_PROJECT_VERSION="8"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="8"

使用Docker仓库进行安装
Docker分为社区版ce和企业版ee,我们选择社区版

第一,先查看是否存在Podman,如果有,就先删除
不删除的话,会与Docker的安装包有如下的冲突:

 - 软件包 containerd.io-1.4.9-3.1.el8.x86_64 与 runc(由 runc-1.0.1-3.module_el8.5.0+870+f792de72.x86_64 提供)冲突
 - 软件包 containerd.io-1.4.9-3.1.el8.x86_64 取代了 runc(由 runc-1.0.1-3.module_el8.5.0+870+f792de72.x86_64 提供)
 - 软件包 containerd.io-1.4.9-3.1.el8.x86_64 与 runc(由 runc-1.0.1-5.module_el8.5.0+878+851f435b.x86_64 提供)冲突

查看是否存在Podman

[root@localhost yum.repos.d]# rpm -q podman
podman-2.0.5-5.module_el8.3.0+512+b3b58dca.x86_64

删除Podman

yum erase podman buildah

一路选择y即可

第二步,安装需要的软件包:yum-utils、device-mapper-persistent-data和lvm2

yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2

详情如下:

Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
CentOS-8-stream - AppStream - mirrors.aliyun.com                8.2 kB/s | 4.4 kB     00:00    
CentOS-8-stream - AppStream - mirrors.aliyun.com                659 kB/s |  22 MB     00:34    

CentOS-8-stream - Base - mir     [            ===             ] ---  B/s |   0  B     --:-- ETA
CentOS-8-stream - Base - mirrors.aliyun.com                     9.9 kB/s | 3.9 kB     00:00    
CentOS-8-stream - Base - mirrors.aliyun.com                     919 kB/s |  22 MB     00:24    
CentOS-8-stream - Extras - mirrors.aliyun.com                    10 kB/s | 2.9 kB     00:00    
Docker CE Stable - x86_64                                        13 kB/s | 3.5 kB     00:00    
Docker CE Stable - x86_64                                        35 kB/s |  25 kB     00:00    
Extra Packages for Enterprise Linux 8 - x86_64                  6.5 kB/s |  10 kB     00:01    
Extra Packages for Enterprise Linux 8 - x86_64                  1.8 MB/s |  11 MB     00:06    
Extra Packages for Enterprise Linux Modular 8 - x86_64          7.0 kB/s | 9.8 kB     00:01    
Extra Packages for Enterprise Linux Modular 8 - x86_64          456 kB/s | 1.0 MB     00:02    
软件包 yum-utils-4.0.21-11.el8.noarch 已安装。
软件包 device-mapper-persistent-data-0.9.0-6.el8.x86_64 已安装。
软件包 lvm2-8:2.03.14-3.el8.x86_64 已安装。
依赖关系解决。
无需任何处理。
完毕!

第三步,设置国内下载镜像,例如阿里云仓库

yum-config-manager \
    --add-repo \
    #这个是默认的仓库
    https://download.docker.com/linux/centos/docker-ce.repo
yum-config-manager \
    --add-repo \
     #设置阿里云仓库
    http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

结果如下:

Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
添加仓库自:http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

第四步:安装docker engine,包括docker-ce、docker-ce-cli和containerd.io

yum install docker-ce docker-ce-cli containerd.io

结果如下:

Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
上次元数据过期检查:0:01:35 前,执行于 20220522日 星期日 092418秒。
依赖关系解决。
================================================================================================
 软件包                  架构   版本                                     仓库              大小
================================================================================================
安装:
 containerd.io           x86_64 1.6.4-3.1.el8                            docker-ce-stable  33 M
 docker-ce               x86_64 3:20.10.16-3.el8                         docker-ce-stable  22 M
 docker-ce-cli           x86_64 1:20.10.16-3.el8                         docker-ce-stable  29 M
升级:
 libsemanage             x86_64 2.9-8.el8                                base             168 k
 policycoreutils         x86_64 2.9-19.el8                               base             374 k
 policycoreutils-python-utils
                         noarch 2.9-19.el8                               base             253 k
 python3-libsemanage     x86_64 2.9-8.el8                                base             128 k
 python3-policycoreutils noarch 2.9-19.el8                               base             2.2 M
 selinux-policy          noarch 3.14.3-98.el8                            base             647 k
 selinux-policy-targeted noarch 3.14.3-98.el8                            base              15 M
安装依赖关系:
 container-selinux       noarch 2:2.180.0-1.module_el8.7.0+1106+45480ee0 AppStream         59 k
 docker-ce-rootless-extras
                         x86_64 20.10.16-3.el8                           docker-ce-stable 4.7 M
 fuse-overlayfs          x86_64 1.8.2-1.module_el8.7.0+1106+45480ee0     AppStream         73 k
 fuse3                   x86_64 3.2.1-12.el8                             base              50 k
 fuse3-libs              x86_64 3.3.0-15.el8                             base              95 k
 libcgroup               x86_64 0.41-19.el8                              base              70 k
 libslirp                x86_64 4.4.0-1.module_el8.6.0+926+8bef8ae7      AppStream         70 k
 slirp4netns             x86_64 1.1.8-2.module_el8.7.0+1106+45480ee0     AppStream         51 k
安装弱的依赖:
 docker-scan-plugin      x86_64 0.17.0-3.el8                             docker-ce-stable 3.8 M

事务概要
================================================================================================
安装  12 软件包
升级   7 软件包

总下载:112 M
确定吗?[y/N]: y
下载软件包:
(1/19): fuse-overlayfs-1.8.2-1.module_el8.7.0+1106+45480ee0.x86 156 kB/s |  73 kB     00:00    
(2/19): container-selinux-2.180.0-1.module_el8.7.0+1106+45480ee 122 kB/s |  59 kB     00:00    
(3/19): libslirp-4.4.0-1.module_el8.6.0+926+8bef8ae7.x86_64.rpm 139 kB/s |  70 kB     00:00    
(4/19): slirp4netns-1.1.8-2.module_el8.7.0+1106+45480ee0.x86_64 266 kB/s |  51 kB     00:00    
(5/19): fuse3-3.2.1-12.el8.x86_64.rpm                           259 kB/s |  50 kB     00:00    
(6/19): fuse3-libs-3.3.0-15.el8.x86_64.rpm                      325 kB/s |  95 kB     00:00    
(7/19): libcgroup-0.41-19.el8.x86_64.rpm                        225 kB/s |  70 kB     00:00    
(8/19): docker-ce-20.10.16-3.el8.x86_64.rpm                     947 kB/s |  22 MB     00:23    
(9/19): docker-ce-rootless-extras-20.10.16-3.el8.x86_64.rpm     870 kB/s | 4.7 MB     00:05    
(10/19): docker-ce-cli-20.10.16-3.el8.x86_64.rpm                1.0 MB/s |  29 MB     00:30    
(11/19): libsemanage-2.9-8.el8.x86_64.rpm                       382 kB/s | 168 kB     00:00    
(12/19): policycoreutils-2.9-19.el8.x86_64.rpm                  555 kB/s | 374 kB     00:00    
(13/19): policycoreutils-python-utils-2.9-19.el8.noarch.rpm     532 kB/s | 253 kB     00:00    
(14/19): python3-libsemanage-2.9-8.el8.x86_64.rpm               385 kB/s | 128 kB     00:00    
(15/19): docker-scan-plugin-0.17.0-3.el8.x86_64.rpm             1.1 MB/s | 3.8 MB     00:03    
(16/19): selinux-policy-3.14.3-98.el8.noarch.rpm                541 kB/s | 647 kB     00:01    
(17/19): python3-policycoreutils-2.9-19.el8.noarch.rpm          608 kB/s | 2.2 MB     00:03    
(18/19): containerd.io-1.6.4-3.1.el8.x86_64.rpm                 899 kB/s |  33 MB     00:37    
(19/19): selinux-policy-targeted-3.14.3-98.el8.noarch.rpm       601 kB/s |  15 MB     00:25    
------------------------------------------------------------------------------------------------
总计                                                            1.9 MB/s | 112 MB     01:00     
Docker CE Stable - x86_64                                       1.3 kB/s | 1.6 kB     00:01    
导入 GPG 公钥 0x621E9F35:
 Userid: "Docker Release (CE rpm) <docker@docker.com>"
 指纹: 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35
 来自: https://download.docker.com/linux/centos/gpg
确定吗?[y/N]: y
导入公钥成功
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
  准备中  :                                                                                 1/1 
  运行脚本: docker-scan-plugin-0.17.0-3.el8.x86_64                                          1/1 
  安装    : docker-scan-plugin-0.17.0-3.el8.x86_64                                         1/26 
  运行脚本: docker-scan-plugin-0.17.0-3.el8.x86_64                                         1/26 
  安装    : docker-ce-cli-1:20.10.16-3.el8.x86_64                                          2/26 
  运行脚本: docker-ce-cli-1:20.10.16-3.el8.x86_64                                          2/26 
  升级    : libsemanage-2.9-8.el8.x86_64                                                   3/26 
  升级    : policycoreutils-2.9-19.el8.x86_64                                              4/26 
  运行脚本: policycoreutils-2.9-19.el8.x86_64                                              4/26 
  升级    : selinux-policy-3.14.3-98.el8.noarch                                            5/26 
  运行脚本: selinux-policy-3.14.3-98.el8.noarch                                            5/26 
  运行脚本: selinux-policy-targeted-3.14.3-98.el8.noarch                                   6/26 
  升级    : selinux-policy-targeted-3.14.3-98.el8.noarch                                   6/26 
  运行脚本: selinux-policy-targeted-3.14.3-98.el8.noarch                                   6/26 
 ^A^H^H^H
  升级    : python3-libsemanage-2.9-8.el8.x86_64                                           7/26 
  升级    : python3-policycoreutils-2.9-19.el8.noarch                                      8/26 
  升级    : policycoreutils-python-utils-2.9-19.el8.noarch                                 9/26 
  运行脚本: container-selinux-2:2.180.0-1.module_el8.7.0+1106+45480ee0.noarch             10/26 
  安装    : container-selinux-2:2.180.0-1.module_el8.7.0+1106+45480ee0.noarch             10/26 
  运行脚本: container-selinux-2:2.180.0-1.module_el8.7.0+1106+45480ee0.noarch             10/26 
  安装    : containerd.io-1.6.4-3.1.el8.x86_64                                            11/26 
  运行脚本: containerd.io-1.6.4-3.1.el8.x86_64                                            11/26 
  运行脚本: libcgroup-0.41-19.el8.x86_64                                                  12/26 
  安装    : libcgroup-0.41-19.el8.x86_64                                                  12/26 
  运行脚本: libcgroup-0.41-19.el8.x86_64                                                  12/26 
  安装    : fuse3-libs-3.3.0-15.el8.x86_64                                                13/26 
  运行脚本: fuse3-libs-3.3.0-15.el8.x86_64                                                13/26 
  安装    : fuse3-3.2.1-12.el8.x86_64                                                     14/26 
  安装    : fuse-overlayfs-1.8.2-1.module_el8.7.0+1106+45480ee0.x86_64                    15/26 
  运行脚本: fuse-overlayfs-1.8.2-1.module_el8.7.0+1106+45480ee0.x86_64                    15/26 
  安装    : libslirp-4.4.0-1.module_el8.6.0+926+8bef8ae7.x86_64                           16/26 
  安装    : slirp4netns-1.1.8-2.module_el8.7.0+1106+45480ee0.x86_64                       17/26 
  安装    : docker-ce-rootless-extras-20.10.16-3.el8.x86_64                               18/26 
  运行脚本: docker-ce-rootless-extras-20.10.16-3.el8.x86_64                               18/26 
  安装    : docker-ce-3:20.10.16-3.el8.x86_64                                             19/26 
  运行脚本: docker-ce-3:20.10.16-3.el8.x86_64                                             19/26 
  清理    : selinux-policy-targeted-3.14.1-61.el8.noarch                                  20/26 
  运行脚本: selinux-policy-targeted-3.14.1-61.el8.noarch                                  20/26 
  清理    : selinux-policy-3.14.1-61.el8.noarch                                           21/26 
  运行脚本: selinux-policy-3.14.1-61.el8.noarch                                           21/26 
  清理    : policycoreutils-python-utils-2.8-16.1.el8.noarch                              22/26 
  清理    : python3-policycoreutils-2.8-16.1.el8.noarch                                   23/26 
  清理    : python3-libsemanage-2.8-5.el8.x86_64                                          24/26 
  运行脚本: policycoreutils-2.8-16.1.el8.x86_64                                           25/26 
  清理    : policycoreutils-2.8-16.1.el8.x86_64                                           25/26 
  清理    : libsemanage-2.8-5.el8.x86_64                                                  26/26 
  运行脚本: container-selinux-2:2.180.0-1.module_el8.7.0+1106+45480ee0.noarch             26/26 
  运行脚本: libsemanage-2.8-5.el8.x86_64                                                  26/26 
  验证    : container-selinux-2:2.180.0-1.module_el8.7.0+1106+45480ee0.noarch              1/26 
  验证    : fuse-overlayfs-1.8.2-1.module_el8.7.0+1106+45480ee0.x86_64                     2/26 
  验证    : libslirp-4.4.0-1.module_el8.6.0+926+8bef8ae7.x86_64                            3/26 
  验证    : slirp4netns-1.1.8-2.module_el8.7.0+1106+45480ee0.x86_64                        4/26 
  验证    : fuse3-3.2.1-12.el8.x86_64                                                      5/26 
  验证    : fuse3-libs-3.3.0-15.el8.x86_64                                                 6/26 
  验证    : libcgroup-0.41-19.el8.x86_64                                                   7/26 
  验证    : containerd.io-1.6.4-3.1.el8.x86_64                                             8/26 
  验证    : docker-ce-3:20.10.16-3.el8.x86_64                                              9/26 
  验证    : docker-ce-cli-1:20.10.16-3.el8.x86_64                                         10/26 
  验证    : docker-ce-rootless-extras-20.10.16-3.el8.x86_64                               11/26 
  验证    : docker-scan-plugin-0.17.0-3.el8.x86_64                                        12/26 
  验证    : libsemanage-2.9-8.el8.x86_64                                                  13/26 
  验证    : libsemanage-2.8-5.el8.x86_64                                                  14/26 
  验证    : policycoreutils-2.9-19.el8.x86_64                                             15/26 
  验证    : policycoreutils-2.8-16.1.el8.x86_64                                           16/26 
  验证    : policycoreutils-python-utils-2.9-19.el8.noarch                                17/26 
  验证    : policycoreutils-python-utils-2.8-16.1.el8.noarch                              18/26 
  验证    : python3-libsemanage-2.9-8.el8.x86_64                                          19/26 
  验证    : python3-libsemanage-2.8-5.el8.x86_64                                          20/26 
  验证    : python3-policycoreutils-2.9-19.el8.noarch                                     21/26 
  验证    : python3-policycoreutils-2.8-16.1.el8.noarch                                   22/26 
  验证    : selinux-policy-3.14.3-98.el8.noarch                                           23/26 
  验证    : selinux-policy-3.14.1-61.el8.noarch                                           24/26 
  验证    : selinux-policy-targeted-3.14.3-98.el8.noarch                                  25/26 
  验证    : selinux-policy-targeted-3.14.1-61.el8.noarch                                  26/26 

已升级:
  libsemanage-2.9-8.el8.x86_64                        policycoreutils-2.9-19.el8.x86_64        
  policycoreutils-python-utils-2.9-19.el8.noarch      python3-libsemanage-2.9-8.el8.x86_64     
  python3-policycoreutils-2.9-19.el8.noarch           selinux-policy-3.14.3-98.el8.noarch      
  selinux-policy-targeted-3.14.3-98.el8.noarch       
已安装:
  container-selinux-2:2.180.0-1.module_el8.7.0+1106+45480ee0.noarch                             
  containerd.io-1.6.4-3.1.el8.x86_64                                                            
  docker-ce-3:20.10.16-3.el8.x86_64                                                             
  docker-ce-cli-1:20.10.16-3.el8.x86_64                                                         
  docker-ce-rootless-extras-20.10.16-3.el8.x86_64                                               
  docker-scan-plugin-0.17.0-3.el8.x86_64                                                        
  fuse-overlayfs-1.8.2-1.module_el8.7.0+1106+45480ee0.x86_64                                    
  fuse3-3.2.1-12.el8.x86_64                                                                     
  fuse3-libs-3.3.0-15.el8.x86_64                                                                
  libcgroup-0.41-19.el8.x86_64                                                                  
  libslirp-4.4.0-1.module_el8.6.0+926+8bef8ae7.x86_64                                           
  slirp4netns-1.1.8-2.module_el8.7.0+1106+45480ee0.x86_64                                       

完毕!

第五步,启动Docker

systemctl start docker

第六步,验证安装是否成功

docker run hello-world

结果如下:


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/

如果上面的hello实例报如下的错误:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:80f31da1ac7b312ba29d65080fddf797dd76acfb870e677f390d5acba9741b17
Status: Downloaded newer image for hello-world:latest
docker: Error response from daemon: failed to create shim task: OCI runtime create failed: unable to retrieve OCI runtime error (open /run/containerd/io.containerd.runtime.v2.task/moby/233c9b6503a6c2f7e6b093011350d5e42c62854dc183b83b3d666a04da27febe/log.json: no such file or directory): runc did not terminate successfully: exit status 127: unknown.

则可以进行如下命令安装

yum install libseccomp-devel

也可以重新配置阿里云镜像,具体就不再此进行说明

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值