docker(centos7.9安装docker)

接上篇:docker(开篇)

目前,CentOS仅发现版中的内核支持Docker。Docker运行在CentOS 7(64-bit)上,要求系统 64位,Linux系统内核3.8以上,这里选择CentOS 7.x

1、确定你是CentOS 7及以上版本

-- 查看CentOS版本号
[root@hadoop100 ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
-- uname -r : 显示操作系统的发行版号
-- uname -a :显示系统名、节点名称、操作系统的发行版号、内核版本等等。
[root@hadoop100 ~]# uname -r
3.10.0-1160.el7.x86_64

 2、卸载旧版本

sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
[root@hadoop100 ~]# sudo yum remove docker \
>                   docker-client \
>                   docker-client-latest \
>                   docker-common \
>                   docker-latest \
>                   docker-latest-logrotate \
>                   docker-logrotate \
>                   docker-engine
已加载插件:fastestmirror, langpacks
参数 docker 没有匹配
参数 docker-client 没有匹配
参数 docker-client-latest 没有匹配
参数 docker-common 没有匹配
参数 docker-latest 没有匹配
参数 docker-latest-logrotate 没有匹配
参数 docker-logrotate 没有匹配
参数 docker-engine 没有匹配
不删除任何软件包

3、yum安装gcc相关

安装 gcc

yum -y install gcc
[root@hadoop100 ~]# yum -y install gcc
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 gcc.x86_64.0.4.8.5-44.el7 将被 安装
--> 正在处理依赖关系 cpp = 4.8.5-44.el7,它被软件包 gcc-4.8.5-44.el7.x86_64 需要
--> 正在处理依赖关系 glibc-devel >= 2.2.90-12,它被软件包 gcc-4.8.5-44.el7.x86_64 需要
--> 正在检查事务
---> 软件包 cpp.x86_64.0.4.8.5-44.el7 将被 安装
---> 软件包 glibc-devel.x86_64.0.2.17-326.el7_9 将被 安装
--> 正在处理依赖关系 glibc-headers = 2.17-326.el7_9,它被软件包 glibc-devel-2.17-326.el7_9.x86_64 需要
--> 正在处理依赖关系 glibc = 2.17-326.el7_9,它被软件包 glibc-devel-2.17-326.el7_9.x86_64 需要
--> 正在处理依赖关系 glibc-headers,它被软件包 glibc-devel-2.17-326.el7_9.x86_64 需要
--> 正在检查事务
---> 软件包 glibc.x86_64.0.2.17-317.el7 将被 升级
--> 正在处理依赖关系 glibc = 2.17-317.el7,它被软件包 glibc-common-2.17-317.el7.x86_64 需要
---> 软件包 glibc.x86_64.0.2.17-326.el7_9 将被 更新
---> 软件包 glibc-headers.x86_64.0.2.17-326.el7_9 将被 安装
--> 正在处理依赖关系 kernel-headers >= 2.2.1,它被软件包 glibc-headers-2.17-326.el7_9.x86_64 需要
--> 正在处理依赖关系 kernel-headers,它被软件包 glibc-headers-2.17-326.el7_9.x86_64 需要
--> 正在检查事务
---> 软件包 glibc-common.x86_64.0.2.17-317.el7 将被 升级
---> 软件包 glibc-common.x86_64.0.2.17-326.el7_9 将被 更新
---> 软件包 kernel-headers.x86_64.0.3.10.0-1160.83.1.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

========================================================================================================================
 Package                       架构                  版本                                  源                      大小
========================================================================================================================
正在安装:
 gcc                           x86_64                4.8.5-44.el7                          base                    16 M
为依赖而安装:
 cpp                           x86_64                4.8.5-44.el7                          base                   5.9 M
 glibc-devel                   x86_64                2.17-326.el7_9                        updates                1.1 M
 glibc-headers                 x86_64                2.17-326.el7_9                        updates                691 k
 kernel-headers                x86_64                3.10.0-1160.83.1.el7                  updates                9.1 M
为依赖而更新:
 glibc                         x86_64                2.17-326.el7_9                        updates                3.6 M
 glibc-common                  x86_64                2.17-326.el7_9                        updates                 12 M

事务概要
========================================================================================================================
安装  1 软件包 (+4 依赖软件包)
升级           ( 2 依赖软件包)

总计:48 M
总下载量:33 M
Downloading packages:
警告:/var/cache/yum/x86_64/7/base/packages/cpp-4.8.5-44.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
cpp-4.8.5-44.el7.x86_64.rpm 的公钥尚未安装
(1/5): cpp-4.8.5-44.el7.x86_64.rpm                                                               | 5.9 MB  00:00:00
glibc-devel-2.17-326.el7_9.x86_64.rpm 的公钥尚未安装
(2/5): glibc-devel-2.17-326.el7_9.x86_64.rpm                                                     | 1.1 MB  00:00:00
(3/5): glibc-headers-2.17-326.el7_9.x86_64.rpm                                                   | 691 kB  00:00:00
(4/5): kernel-headers-3.10.0-1160.83.1.el7.x86_64.rpm                                            | 9.1 MB  00:00:00
(5/5): gcc-4.8.5-44.el7.x86_64.rpm                                                               |  16 MB  00:00:01
------------------------------------------------------------------------------------------------------------------------
总计                                                                                     24 MB/s |  33 MB  00:00:01file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 检索密钥
导入 GPG key 0xF4A80EB5:
 用户ID     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 指纹       : 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 软件包     : centos-release-7-9.2009.0.el7.centos.x86_64 (@anaconda)
 来自       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在更新    : glibc-2.17-326.el7_9.x86_64                                                                         1/9
  正在更新    : glibc-common-2.17-326.el7_9.x86_64                                                                  2/9
  正在安装    : cpp-4.8.5-44.el7.x86_64                                                                             3/9
  正在安装    : kernel-headers-3.10.0-1160.83.1.el7.x86_64                                                          4/9
  正在安装    : glibc-headers-2.17-326.el7_9.x86_64                                                                 5/9
  正在安装    : glibc-devel-2.17-326.el7_9.x86_64                                                                   6/9
  正在安装    : gcc-4.8.5-44.el7.x86_64                                                                             7/9
  清理        : glibc-2.17-317.el7.x86_64                                                                           8/9
  清理        : glibc-common-2.17-317.el7.x86_64                                                                    9/9
  验证中      : glibc-common-2.17-326.el7_9.x86_64                                                                  1/9
  验证中      : glibc-2.17-326.el7_9.x86_64                                                                         2/9
  验证中      : glibc-devel-2.17-326.el7_9.x86_64                                                                   3/9
  验证中      : cpp-4.8.5-44.el7.x86_64                                                                             4/9
  验证中      : glibc-headers-2.17-326.el7_9.x86_64                                                                 5/9
  验证中      : gcc-4.8.5-44.el7.x86_64                                                                             6/9
  验证中      : kernel-headers-3.10.0-1160.83.1.el7.x86_64                                                          7/9
  验证中      : glibc-2.17-317.el7.x86_64                                                                           8/9
  验证中      : glibc-common-2.17-317.el7.x86_64                                                                    9/9

已安装:
  gcc.x86_64 0:4.8.5-44.el7

作为依赖被安装:
  cpp.x86_64 0:4.8.5-44.el7                               glibc-devel.x86_64 0:2.17-326.el7_9
  glibc-headers.x86_64 0:2.17-326.el7_9                   kernel-headers.x86_64 0:3.10.0-1160.83.1.el7

作为依赖被升级:
  glibc.x86_64 0:2.17-326.el7_9                           glibc-common.x86_64 0:2.17-326.el7_9

完毕!
View Code

安装 gcc-c++

yum -y install gcc-c++
[root@hadoop100 ~]# yum -y install gcc-c++
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 gcc-c++.x86_64.0.4.8.5-44.el7 将被 安装
--> 正在处理依赖关系 libstdc++-devel = 4.8.5-44.el7,它被软件包 gcc-c++-4.8.5-44.el7.x86_64 需要
--> 正在检查事务
---> 软件包 libstdc++-devel.x86_64.0.4.8.5-44.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

========================================================================================================================
 Package                           架构                     版本                           源                      大小
========================================================================================================================
正在安装:
 gcc-c++                           x86_64                   4.8.5-44.el7                   base                   7.2 M
为依赖而安装:
 libstdc++-devel                   x86_64                   4.8.5-44.el7                   base                   1.5 M

事务概要
========================================================================================================================
安装  1 软件包 (+1 依赖软件包)

总下载量:8.7 M
安装大小:25 M
Downloading packages:
(1/2): libstdc++-devel-4.8.5-44.el7.x86_64.rpm                                                   | 1.5 MB  00:00:00
(2/2): gcc-c++-4.8.5-44.el7.x86_64.rpm                                                           | 7.2 MB  00:00:00
------------------------------------------------------------------------------------------------------------------------
总计                                                                                     15 MB/s | 8.7 MB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : libstdc++-devel-4.8.5-44.el7.x86_64                                                                 1/2
  正在安装    : gcc-c++-4.8.5-44.el7.x86_64                                                                         2/2
  验证中      : gcc-c++-4.8.5-44.el7.x86_64                                                                         1/2
  验证中      : libstdc++-devel-4.8.5-44.el7.x86_64                                                                 2/2

已安装:
  gcc-c++.x86_64 0:4.8.5-44.el7

作为依赖被安装:
  libstdc++-devel.x86_64 0:4.8.5-44.el7

完毕!
View Code

 4、安装需要的软件包

 安装 yum-utils

yum install -y yum-utils
[root@hadoop100 ~]# sudo yum install -y yum-utils
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
软件包 yum-utils-1.1.31-54.el7_8.noarch 已安装并且是最新版本
无须任何处理
View Code

5、设置stable镜像仓库

方式1:官网推荐(中国大陆不推荐使用,可能会访问超时)

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

方式2:推荐使用(阿里云)

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@hadoop100 ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
已加载插件:fastestmirror, langpacks
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
View Code

6、更新yum软件包索引

官网没有,但建议执行

yum makecache fast
[root@hadoop100 ~]# yum makecache fast
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                             | 3.6 kB  00:00:00
docker-ce-stable                                                                                 | 3.5 kB  00:00:00
extras                                                                                           | 2.9 kB  00:00:00
updates                                                                                          | 2.9 kB  00:00:00
元数据缓存已建立
View Code

7、安装 docker engine

yum install docker-ce docker-ce-cli containerd.io
[root@hadoop100 ~]# yum install docker-ce docker-ce-cli containerd.io
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 containerd.io.x86_64.0.1.6.15-3.1.el7 将被 安装
--> 正在处理依赖关系 container-selinux >= 2:2.74,它被软件包 containerd.io-1.6.15-3.1.el7.x86_64 需要
---> 软件包 docker-ce.x86_64.3.20.10.23-3.el7 将被 安装
--> 正在处理依赖关系 docker-ce-rootless-extras,它被软件包 3:docker-ce-20.10.23-3.el7.x86_64 需要
---> 软件包 docker-ce-cli.x86_64.1.20.10.23-3.el7 将被 安装
--> 正在处理依赖关系 docker-scan-plugin(x86-64),它被软件包 1:docker-ce-cli-20.10.23-3.el7.x86_64 需要
--> 正在检查事务
---> 软件包 container-selinux.noarch.2.2.119.2-1.911c772.el7_8 将被 安装
---> 软件包 docker-ce-rootless-extras.x86_64.0.20.10.23-3.el7 将被 安装
--> 正在处理依赖关系 fuse-overlayfs >= 0.7,它被软件包 docker-ce-rootless-extras-20.10.23-3.el7.x86_64 需要
--> 正在处理依赖关系 slirp4netns >= 0.4,它被软件包 docker-ce-rootless-extras-20.10.23-3.el7.x86_64 需要
---> 软件包 docker-scan-plugin.x86_64.0.0.23.0-3.el7 将被 安装
--> 正在检查事务
---> 软件包 fuse-overlayfs.x86_64.0.0.7.2-6.el7_8 将被 安装
--> 正在处理依赖关系 libfuse3.so.3(FUSE_3.2)(64bit),它被软件包 fuse-overlayfs-0.7.2-6.el7_8.x86_64 需要
--> 正在处理依赖关系 libfuse3.so.3(FUSE_3.0)(64bit),它被软件包 fuse-overlayfs-0.7.2-6.el7_8.x86_64 需要
--> 正在处理依赖关系 libfuse3.so.3()(64bit),它被软件包 fuse-overlayfs-0.7.2-6.el7_8.x86_64 需要
---> 软件包 slirp4netns.x86_64.0.0.4.3-4.el7_8 将被 安装
--> 正在检查事务
---> 软件包 fuse3-libs.x86_64.0.3.6.1-4.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

========================================================================================================================
 Package                            架构            版本                                源                         大小
========================================================================================================================
正在安装:
 containerd.io                      x86_64          1.6.15-3.1.el7                      docker-ce-stable           33 M
 docker-ce                          x86_64          3:20.10.23-3.el7                    docker-ce-stable           22 M
 docker-ce-cli                      x86_64          1:20.10.23-3.el7                    docker-ce-stable           30 M
为依赖而安装:
 container-selinux                  noarch          2:2.119.2-1.911c772.el7_8           extras                     40 k
 docker-ce-rootless-extras          x86_64          20.10.23-3.el7                      docker-ce-stable          8.5 M
 docker-scan-plugin                 x86_64          0.23.0-3.el7                        docker-ce-stable          3.8 M
 fuse-overlayfs                     x86_64          0.7.2-6.el7_8                       extras                     54 k
 fuse3-libs                         x86_64          3.6.1-4.el7                         extras                     82 k
 slirp4netns                        x86_64          0.4.3-4.el7_8                       extras                     81 k

事务概要
========================================================================================================================
安装  3 软件包 (+6 依赖软件包)

总下载量:97 M
安装大小:358 M
Is this ok [y/d/N]: y
Downloading packages:
(1/9): container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm                                      |  40 kB  00:00:00
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-20.10.23-3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
docker-ce-20.10.23-3.el7.x86_64.rpm 的公钥尚未安装
(2/9): docker-ce-20.10.23-3.el7.x86_64.rpm                                                       |  22 MB  00:04:22
(3/9): containerd.io-1.6.15-3.1.el7.x86_64.rpm                                                   |  33 MB  00:06:40
(4/9): docker-ce-rootless-extras-20.10.23-3.el7.x86_64.rpm                                       | 8.5 MB  00:01:45
(5/9): fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm                                                   |  54 kB  00:00:00
(6/9): slirp4netns-0.4.3-4.el7_8.x86_64.rpm                                                      |  81 kB  00:00:00
(7/9): fuse3-libs-3.6.1-4.el7.x86_64.rpm                                                         |  82 kB  00:00:00
(8/9): docker-scan-plugin-0.23.0-3.el7.x86_64.rpm                                                | 3.8 MB  00:00:47
(9/9): docker-ce-cli-20.10.23-3.el7.x86_64.rpm                                                   |  30 MB  00:06:16
------------------------------------------------------------------------------------------------------------------------
总计                                                                                    156 kB/s |  97 MB  00:10:39
从 https://mirrors.aliyun.com/docker-ce/linux/centos/gpg 检索密钥
导入 GPG key 0x621E9F35:
 用户ID     : "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
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch                                                  1/9
  正在安装    : containerd.io-1.6.15-3.1.el7.x86_64                                                                 2/9
  正在安装    : slirp4netns-0.4.3-4.el7_8.x86_64                                                                    3/9
  正在安装    : fuse3-libs-3.6.1-4.el7.x86_64                                                                       4/9
  正在安装    : fuse-overlayfs-0.7.2-6.el7_8.x86_64                                                                 5/9
  正在安装    : docker-scan-plugin-0.23.0-3.el7.x86_64                                                              6/9
  正在安装    : 1:docker-ce-cli-20.10.23-3.el7.x86_64                                                               7/9
  正在安装    : docker-ce-rootless-extras-20.10.23-3.el7.x86_64                                                     8/9
  正在安装    : 3:docker-ce-20.10.23-3.el7.x86_64                                                                   9/9
  验证中      : docker-scan-plugin-0.23.0-3.el7.x86_64                                                              1/9
  验证中      : fuse3-libs-3.6.1-4.el7.x86_64                                                                       2/9
  验证中      : fuse-overlayfs-0.7.2-6.el7_8.x86_64                                                                 3/9
  验证中      : 1:docker-ce-cli-20.10.23-3.el7.x86_64                                                               4/9
  验证中      : slirp4netns-0.4.3-4.el7_8.x86_64                                                                    5/9
  验证中      : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch                                                  6/9
  验证中      : docker-ce-rootless-extras-20.10.23-3.el7.x86_64                                                     7/9
  验证中      : 3:docker-ce-20.10.23-3.el7.x86_64                                                                   8/9
  验证中      : containerd.io-1.6.15-3.1.el7.x86_64                                                                 9/9

已安装:
  containerd.io.x86_64 0:1.6.15-3.1.el7    docker-ce.x86_64 3:20.10.23-3.el7    docker-ce-cli.x86_64 1:20.10.23-3.el7

作为依赖被安装:
  container-selinux.noarch 2:2.119.2-1.911c772.el7_8          docker-ce-rootless-extras.x86_64 0:20.10.23-3.el7
  docker-scan-plugin.x86_64 0:0.23.0-3.el7                    fuse-overlayfs.x86_64 0:0.7.2-6.el7_8
  fuse3-libs.x86_64 0:3.6.1-4.el7                             slirp4netns.x86_64 0:0.4.3-4.el7_8

完毕!
View Code

8、启动docker

systemctl start docker

9、测试

-- 查看当前docker版本
docker version
-- 运行测试用例
docker run hello-word
[root@hadoop100 ~]# systemctl start docker
[root@hadoop100 ~]# docker version
Client: Docker Engine - Community
 Version:           20.10.23
 API version:       1.41
 Go version:        go1.18.10
 Git commit:        7155243
 Built:             Thu Jan 19 17:36:21 2023
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.23
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.10
  Git commit:       6051f14
  Built:            Thu Jan 19 17:34:26 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.15
  GitCommit:        5b842e528e99d4d4c1686467debf2bd4b88ecd86
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
View Code
[root@hadoop100 ~]# docker run hello-world
-- 无法在本地找到镜像
Unable to find image 'hello-world:latest' locally
-- 从远程仓库拉取
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:aa0cc8055b82dc2509bed2e19b275c8f463506616377219d9642221ab53cf9fe
-- 下载了一个最新的镜像
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/
View Code

centos安装docker完成!

10、卸载docker

-- 停止docker
systemctl stop docker
-- 卸载docker引擎
yum remove docker-ce docker-ce-cli containerd.io

-- 删除相关配置文件
rm -rf /var/lib/docker
rm -rf /var/lib/containerd

 

接下篇:docker(镜像加速器)

 
posted @ 2023-01-29 14:28  DHaiLin  阅读(1833)  评论(2编辑  收藏  举报