CentOS 7安装Docker-ce

0.卸载旧版本
较旧的 Docker 版本称为 docker 或 docker-engine 。如果已安装这些程序,请卸载它们以及相关的依赖项。
#yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
1.准备:安装所需的软件包。yum-utils 提供了 yum-config-manager ,并且 device mapper 存储驱动程序需要 device-mapper-persistent-data 和 lvm2。
[root@centos7 ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
epel/x86_64/metalink | 8.2 kB 00:00

  • base: mirrors.aliyun.com
  • epel: mirrors.aliyun.com
  • extras: mirrors.aliyun.com
  • updates: mirrors.aliyun.com
    base | 3.6 kB 00:00
    epel | 5.3 kB 00:00
    extras | 2.9 kB 00:00
    updates | 2.9 kB 00:00
    (1/2): epel/x86_64/updateinfo | 1.0 MB 00:02
    (2/2): epel/x86_64/primary_db | 6.9 MB 00:03
    软件包 yum-utils-1.1.31-52.el7.noarch 已安装并且是最新版本
    软件包 device-mapper-persistent-data-0.8.5-1.el7.x86_64 已安装并且是最新版本
    软件包 7:lvm2-2.02.185-2.el7_7.2.x86_64 已安装并且是最新版本
    无须任何处理
    2.使用以下命令来设置稳定的仓库。
    [root@centos7 ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    已加载插件:fastestmirror, langpacks
    adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
    grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
    repo saved to /etc/yum.repos.d/docker-ce.repo
  1. [root@centos7 ~]#yum-config-manager --enable docker-ce-edge(开启docker-ce-edge源)
    已加载插件:fastestmirror, langpacks
    ============================= repo: docker-ce-edge =============================
    [docker-ce-edge]
    async = True
    bandwidth = 0
    base_persistdir = /var/lib/yum/repos/x86_64/7
    baseurl = https://download.docker.com/linux/centos/7/x86_64/edge
    cache = 0
    cachedir = /var/cache/yum/x86_64/7/docker-ce-edge
    check_config_file_age = True
    compare_providers_priority = 80
    cost = 1000
    deltarpm_metadata_percentage = 100
    deltarpm_percentage =
    enabled = 1
    enablegroups = True
    exclude =
    failovermethod = priority
    ftp_disable_epsv = False
    gpgcadir = /var/lib/yum/repos/x86_64/7/docker-ce-edge/gpgcadir
    gpgcakey =
    gpgcheck = True
    gpgdir = /var/lib/yum/repos/x86_64/7/docker-ce-edge/gpgdir
    gpgkey = https://download.docker.com/linux/centos/gpg
    hdrdir = /var/cache/yum/x86_64/7/docker-ce-edge/headers
    http_caching = all
    includepkgs =
    ip_resolve =
    keepalive = True
    keepcache = False
    mddownloadpolicy = sqlite
    mdpolicy = group:small
    mediaid =
    metadata_expire = 21600
    metadata_expire_filter = read-only:present
    metalink =
    minrate = 0
    mirrorlist =
    mirrorlist_expire = 86400
    name = Docker CE Edge - x86_64
    old_base_cache_dir =
    password =
    persistdir = /var/lib/yum/repos/x86_64/7/docker-ce-edge
    pkgdir = /var/cache/yum/x86_64/7/docker-ce-edge/packages
    proxy = False
    proxy_dict =
    proxy_password =
    proxy_username =
    repo_gpgcheck = False
    retries = 10
    skip_if_unavailable = False
    ssl_check_cert_permissions = True
    sslcacert =
    sslclientcert =
    sslclientkey =
    sslverify = True
    throttle = 0
    timeout = 30.0
    ui_id = docker-ce-edge/x86_64
    ui_repoid_vars = releasever,
    basearch
    username =
    4.[root@centos7 ~]#yum-config-manager --enable docker-ce-test(可不开启)
    已加载插件:fastestmirror, langpacks
    ============================= repo: docker-ce-test =============================
    [docker-ce-test]
    async = True
    bandwidth = 0
    base_persistdir = /var/lib/yum/repos/x86_64/7
    baseurl = https://download.docker.com/linux/centos/7/x86_64/test
    cache = 0
    cachedir = /var/cache/yum/x86_64/7/docker-ce-test
    check_config_file_age = True
    compare_providers_priority = 80
    cost = 1000
    deltarpm_metadata_percentage = 100
    deltarpm_percentage =
    enabled = 1
    enablegroups = True
    exclude =
    failovermethod = priority
    ftp_disable_epsv = False
    gpgcadir = /var/lib/yum/repos/x86_64/7/docker-ce-test/gpgcadir
    gpgcakey =
    gpgcheck = True
    gpgdir = /var/lib/yum/repos/x86_64/7/docker-ce-test/gpgdir
    gpgkey = https://download.docker.com/linux/centos/gpg
    hdrdir = /var/cache/yum/x86_64/7/docker-ce-test/headers
    http_caching = all
    includepkgs =
    ip_resolve =
    keepalive = True
    keepcache = False
    mddownloadpolicy = sqlite
    mdpolicy = group:small
    mediaid =
    metadata_expire = 21600
    metadata_expire_filter = read-only:present
    metalink =
    minrate = 0
    mirrorlist =
    mirrorlist_expire = 86400
    name = Docker CE Test - x86_64
    old_base_cache_dir =
    password =
    persistdir = /var/lib/yum/repos/x86_64/7/docker-ce-test
    pkgdir = /var/cache/yum/x86_64/7/docker-ce-test/packages
    proxy = False
    proxy_dict =
    proxy_password =
    proxy_username =
    repo_gpgcheck = False
    retries = 10
    skip_if_unavailable = False
    ssl_check_cert_permissions = True
    sslcacert =
    sslclientcert =
    sslclientkey =
    sslverify = True
    throttle = 0
    timeout = 30.0
    ui_id = docker-ce-test/x86_64
    ui_repoid_vars = releasever,
    basearch
    username =
    5.[root@centos7 ~]#yum makecache fast(更新缓存,源立即生效)
    已加载插件:fastestmirror, langpacks
    Loading mirror speeds from cached hostfile
    epel/x86_64/metalink | 8.2 kB 00:00
  • base: mirrors.aliyun.com
  • epel: mirrors.aliyun.com
  • extras: mirrors.aliyun.com
  • updates: mirrors.aliyun.com
    base | 3.6 kB 00:00
    docker-ce-edge | 3.5 kB 00:00
    docker-ce-stable | 3.5 kB 00:00
    docker-ce-test | 3.5 kB 00:00
    epel | 5.3 kB 00:00
    extras | 2.9 kB 00:00
    updates | 2.9 kB 00:00
    (1/6): docker-ce-stable/x86_64/updateinfo | 55 B 00:01
    (2/6): docker-ce-test/x86_64/updateinfo | 55 B 00:01
    (3/6): docker-ce-test/x86_64/primary_db | 110 kB 00:00
    (4/6): docker-ce-stable/x86_64/primary_db | 37 kB 00:01
    (5/6): docker-ce-edge/x86_64/updateinfo | 55 B 00:01
    (6/6): docker-ce-edge/x86_64/primary_db | 41 kB 00:01
    元数据缓存已建立
    6.安装 Docker Engine-Community
    6.1要安装特定版本的 Docker Engine-Community
    6.1.1列出并排序您存储库中可用的版本。此示例按版本号(从高到低)对结果进行排序。
    [root@centos7 ~]#yum list docker-ce –showduplicates | sort -r
    已加载插件:fastestmirror, langpacks
    已安装的软件包
    可安装的软件包
  • updates: mirrors.aliyun.com
    Loading mirror speeds from cached hostfile
  • extras: mirrors.aliyun.com
  • epel: mirrors.aliyun.com
    docker-ce.x86_64 3:19.03.5-3.el7 docker-ce-test
    docker-ce.x86_64 3:19.03.5-3.el7 docker-ce-stable
    docker-ce.x86_64 3:19.03.5-3.el7 docker-ce-edge
    docker-ce.x86_64 3:19.03.5-3.el7 @docker-ce-edge
    docker-ce.x86_64 3:19.03.5-2.1.rc1.el7 docker-ce-test
    docker-ce.x86_64 3:19.03.5-1.2.beta2.el7 docker-ce-test
    docker-ce.x86_64 3:19.03.5-1.1.beta1.el7 docker-ce-test
    docker-ce.x86_64 3:19.03.4-3.el7 docker-ce-test
    docker-ce.x86_64 3:19.03.4-3.el7 docker-ce-stable
    docker-ce.x86_64 3:19.03.4-3.el7 docker-ce-edge
    docker-ce.x86_64 3:19.03.4-2.1.rc1.el7 docker-ce-test
    docker-ce.x86_64 3:19.03.3-3.el7 docker-ce-test
    docker-ce.x86_64 3:19.03.3-3.el7 docker-ce-stable
    docker-ce.x86_64 3:19.03.3-3.el7 docker-ce-edge
    docker-ce.x86_64 3:19.03.3-2.1.rc1.el7 docker-ce-test
    docker-ce.x86_64 3:19.03.3-1.2.beta2.el7 docker-ce-test
    docker-ce.x86_64 3:19.03.3-1.1.beta1.el7 docker-ce-test
    docker-ce.x86_64 3:19.03.2-3.el7 docker-ce-test
    docker-ce.x86_64 3:19.03.2-3.el7 docker-ce-stable
    docker-ce.x86_64 3:19.03.2-3.el7 docker-ce-edge
    docker-ce.x86_64 3:19.03.2-2.1.rc1.el7 docker-ce-test
    docker-ce.x86_64 3:19.03.2-1.1.beta1.el7 docker-ce-test
    docker-ce.x86_64 3:19.03.1-3.el7 docker-ce-test
    docker-ce.x86_64 3:19.03.1-3.el7 docker-ce-stable
    docker-ce.x86_64 3:19.03.1-3.el7 docker-ce-edge
    docker-ce.x86_64 3:19.03.0-3.el7 docker-ce-test
    docker-ce.x86_64 3:19.03.0-3.el7 docker-ce-stable
    docker-ce.x86_64 3:19.03.0-3.el7 docker-ce-edge
    docker-ce.x86_64 3:19.03.0-2.3.rc3.el7 docker-ce-test
    docker-ce.x86_64 3:19.03.0-2.2.rc2.el7 docker-ce-test
    docker-ce.x86_64 3:19.03.0-1.5.beta5.el7 docker-ce-test
    docker-ce.x86_64 3:19.03.0-1.4.beta4.el7 docker-ce-test
    docker-ce.x86_64 3:19.03.0-1.3.beta3.el7 docker-ce-test
    docker-ce.x86_64 3:19.03.0-1.2.beta2.el7 docker-ce-test
    docker-ce.x86_64 3:19.03.0-1.1.beta1.el7 docker-ce-test


docker-ce.x86_64 17.03.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.2.ce-0.1.rc1.el7.centos docker-ce-test
docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.1.ce-0.1.rc1.el7.centos docker-ce-test
docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable

  • base: mirrors.aliyun.com
    6.1.2通过其完整的软件包名称安装特定版本,该软件包名称是软件包名称(docker-ce)加上版本字符串(第二列),从第一个冒号(:)一直到第一个连字符,并用连字符(-)分隔。例如:docker-ce-18.09.1。
    #yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
    6.2安装最新版本的 Docker Engine-Community 和 containerd
    [root@centos7 ~]#yum install docker-ce (docker-ce-cli containerd.io)
    已加载插件:fastestmirror, langpacks
    Loading mirror speeds from cached hostfile
  • base: mirrors.aliyun.com
  • epel: mirrors.aliyun.com
  • extras: mirrors.aliyun.com
  • updates: mirrors.aliyun.com
    正在解决依赖关系
    –> 正在检查事务
    —> 软件包 docker-ce.x86_64.3.19.03.5-3.el7 将被 安装
    –> 正在处理依赖关系 container-selinux >= 2:2.74,它被软件包 3:docker-ce-19.03.5-3.el7.x86_64 需要
    –> 正在处理依赖关系 containerd.io >= 1.2.2-3,它被软件包 3:docker-ce-19.03.5-3.el7.x86_64 需要
    –> 正在处理依赖关系 docker-ce-cli,它被软件包 3:docker-ce-19.03.5-3.el7.x86_64 需要
    –> 正在检查事务
    —> 软件包 container-selinux.noarch.2.2.107-3.el7 将被 安装
    —> 软件包 containerd.io.x86_64.0.1.2.10-3.2.el7 将被 安装
    —> 软件包 docker-ce-cli.x86_64.1.19.03.5-3.el7 将被 安装
    –> 解决依赖关系完成


总计 2.0 MB/s | 87 MB 00:43
从 https://download.docker.com/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://download.docker.com/linux/centos/gpg
是否继续?[y/N]:y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : 2:container-selinux-2.107-3.el7.noarch 1/4
正在安装 : containerd.io-1.2.10-3.2.el7.x86_64 2/4
正在安装 : 1:docker-ce-cli-19.03.5-3.el7.x86_64 3/4
正在安装 : 3:docker-ce-19.03.5-3.el7.x86_64 4/4
验证中 : containerd.io-1.2.10-3.2.el7.x86_64 1/4
验证中 : 1:docker-ce-cli-19.03.5-3.el7.x86_64 2/4
验证中 : 2:container-selinux-2.107-3.el7.noarch 3/4
验证中 : 3:docker-ce-19.03.5-3.el7.x86_64 4/4

已安装:
docker-ce.x86_64 3:19.03.5-3.el7

作为依赖被安装:
container-selinux.noarch 2:2.107-3.el7 containerd.io.x86_64 0:1.2.10-3.2.el7
docker-ce-cli.x86_64 1:19.03.5-3.el7

完毕!
7.[root@centos7 ~]#systemctl start docker
[root@centos7 ~]#systemctl enable docker
[root@centos7 ~]#systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since 二 2019-12-03 17:03:31 CST; 9s ago
Docs: https://docs.docker.com
Main PID: 29576 (dockerd)
Tasks: 10
Memory: 55.8M
CGroup: /system.slice/docker.service
└─29576 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/con…

12月 03 17:03:09 centos7.cqdzzx.cn dockerd[29576]: time="2019-12-03T17:03:09…
12月 03 17:03:09 centos7.cqdzzx.cn dockerd[29576]: time="2019-12-03T17:03:09…
12月 03 17:03:09 centos7.cqdzzx.cn dockerd[29576]: time="2019-12-03T17:03:09…
12月 03 17:03:09 centos7.cqdzzx.cn dockerd[29576]: time="2019-12-03T17:03:09…
12月 03 17:03:15 centos7.cqdzzx.cn dockerd[29576]: time="2019-12-03T17:03:15…
12月 03 17:03:19 centos7.cqdzzx.cn dockerd[29576]: time="2019-12-03T17:03:19…
12月 03 17:03:29 centos7.cqdzzx.cn dockerd[29576]: time="2019-12-03T17:03:29…
12月 03 17:03:29 centos7.cqdzzx.cn dockerd[29576]: time="2019-12-03T17:03:29…
12月 03 17:03:31 centos7.cqdzzx.cn systemd[1]: Started Docker Application C…
12月 03 17:03:31 centos7.cqdzzx.cn dockerd[29576]: time="2019-12-03T17:03:31…
Hint: Some lines were ellipsized, use -l to show in full.
8.测试
#docker run hello-world
Unable to find image ‘hello-world:latest’ locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:4df8ca8a7e309c256d60d7971ea14c27672fc0d10c5f303856d7bc48f8cc17ff
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/
9.设置加速

对于CentOS7 ,为docker设置加速可这样做:
vim /etc/docker/daemon.json
输入以下内容:
{
“registry-mirrors”:[“https://6kx4zyno.mirror.aliyuncs.com”]
}
保存退出后,再重启docker。

### 回答1: 1. 卸载旧版本的Docker 如果您已经安装了旧版本的Docker,需要先卸载旧版本的Docker。 sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine 2. 安装必要的软件包 sudo yum install -y yum-utils \ device-mapper-persistent-data \ lvm2 3. 添加Docker的官方GPG密钥 sudo yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo 4. 安装Docker CE sudo yum install docker-ce docker-ce-cli containerd.io 5. 启动Docker sudo systemctl start docker 6. 验证Docker是否安装成功 sudo docker run hello-world 如果您看到了以下输出,则说明Docker已经成功安装并运行: Hello from Docker! This message shows that your installation appears to be working correctly. 7. 设置Docker开机自启 sudo systemctl enable docker 现在,您已经成功地在CentOS 7上安装Docker CE。 ### 回答2: CentOS7是一种常见的Linux操作系统。Docker CE是一种流行的容器化平台。本文将介绍如何在CentOS7上安装Docker CE。 1. 升级和安装必要的软件包 首先,更新系统并安装必要的软件包: sudo yum update sudo yum install -y yum-utils device-mapper-persistent-data lvm2 2. 添加Docker CE的yum软件源 添加Docker CE的yum软件源到系统中: sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo 3. 安装Docker CE 运行以下命令以安装最新版本的Docker CE: sudo yum install docker-ce 4. 启动Docker服务 启动Docker服务: sudo systemctl start docker 使用以下命令验证Docker是否已正确安装: sudo docker run hello-world 这将启动一个测试容器并输出一些信息。 5. 设置Docker服务自启动 配置Docker服务在机器启动时自动启动: sudo systemctl enable docker 完成以上步骤后,便成功将Docker CE安装CentOS7上,并可以使用您的容器运行镜像。 注:如果您使用的是具有安全策略和防火墙规则的Linux,需要调整这些规则才能运行Docker和容器。 ### 回答3: CentOS 7是一种流行的Linux操作系统版本,适用于服务器和云计算环境。Docker CE是一个开源的容器平台,可以轻松地打包应用程序和依赖项,并运行在任何地方,而不必担心与操作系统的兼容性问题。在本文中,我们将向您介绍如何在CentOS 7上安装Docker CE。 步骤1: 升级系统 在开始安装之前,我们必须要确保我们使用的是最新的软件包和依赖项。运行以下命令可以升级CentOS 7系统。 sudo yum update -y 步骤2: 安装必备软件包 在安装Docker CE之前,我们必须先安装一些必备的软件包,比如yum-utils,用于管理Docker软件包的特定仓库。 sudo yum install -y yum-utils device-mapper-persistent-data lvm2 步骤3: 添加docker-ce的仓库 Docker CE软件包不在默认的CentOS 7存储库中。因此,我们需要手动添加Docker CE仓库。通过运行以下命令可以添加Docker CE官方仓库到CentOS 7系统中。 sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo 步骤4: 安装Docker CE 添加完Docker CE仓库之后,我们可以安装Docker CE了。以下命令可以安装Docker CE。 sudo yum install -y docker-ce 安装完成后,我们可以通过以下命令启动Docker CE服务,并使其在系统启动时自动启动。 sudo systemctl start docker sudo systemctl enable docker 步骤5: 验证Docker CE 安装完成后,我们可以使用以下命令来验证Docker是否成功安装docker version 这会显示Docker CE的版本号和相关信息。 至此,CentOS 7上的Docker CE安装已成功完成。现在您可以开始构建和管理容器了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值