镜像下载、域名解析、时间同步请点击 阿里巴巴开源镜像站
在新主机上首次安装Docker Engine之前,需要设置Docker存储库。之后,您可以从存储库安装和更新Docker。 设置存储库 安装yum-utils软件包(提供yum-config-manager 实用程序)并设置稳定的存储库。
[root@localhost ~]# yum install -y yum-utils已加载插件:fastestmirror, langpacksLoading mirror speeds from cached hostfile * base: mirror.lzu.edu.cn * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com正在解决依赖关系--> 正在检查事务---> 软件包 yum-utils.noarch.0.1.1.31-24.el7 将被 升级---> 软件包 yum-utils.noarch.0.1.1.31-52.el7 将被 更新--> 正在处理依赖关系 yum >= 3.4.3-143,它被软件包 yum-utils-1.1.31-52.el7.noarch 需要--> 正在检查事务---> 软件包 yum.noarch.0.3.4.3-118.el7.centos 将被 升级---> 软件包 yum.noarch.0.3.4.3-163.el7.centos 将被 更新--> 正在处理依赖关系 rpm >= 4.11.3-22,它被软件包 yum-3.4.3-163.el7.centos.noarch 需要--> 正在处理依赖关系 python-urlgrabber >= 3.10-8,它被软件包 yum-3.4.3-163.el7.centos.noarch 需要--> 正在检查事务---> 软件包 python-urlgrabber.noarch.0.3.10-4.el7 将被 升级---> 软件包 python-urlgrabber.noarch.0.3.10-9.el7 将被 更新---> 软件包 rpm.x86_64.0.4.11.1-16.el7 将被 升级--> 正在处理依赖关系 rpm = 4.11.1-16.el7,它被软件包 rpm-python-4.11.1-16.el7.x86_64 需要--> 正在处理依赖关系 rpm = 4.11.1-16.el7,它被软件包 rpm-libs-4.11.1-16.el7.x86_64 需要---> 软件包 rpm.x86_64.0.4.11.3-40.el7 将被 更新--> 正在检查事务---> 软件包 rpm-libs.x86_64.0.4.11.1-16.el7 将被 升级--> 正在处理依赖关系 rpm-libs(x86-64) = 4.11.1-16.el7,它被软件包 rpm-build-libs-4.11.1-16.el7.x86_64 需要---> 软件包 rpm-libs.x86_64.0.4.11.3-40.el7 将被 更新---> 软件包 rpm-python.x86_64.0.4.11.1-16.el7 将被 升级---> 软件包 rpm-python.x86_64.0.4.11.3-40.el7 将被 更新--> 正在检查事务---> 软件包 rpm-build-libs.x86_64.0.4.11.1-16.el7 将被 升级---> 软件包 rpm-build-libs.x86_64.0.4.11.3-40.el7 将被 更新--> 解决依赖关系完成依赖关系解决============================================================================================================================================================================================================================ Package 架构 版本 源 大小============================================================================================================================================================================================================================正在更新: yum-utils noarch 1.1.31-52.el7 base 121 k为依赖而更新: python-urlgrabber noarch 3.10-9.el7 base 108 k rpm x86_64 4.11.3-40.el7 base 1.2 M rpm-build-libs x86_64 4.11.3-40.el7 base 107 k rpm-libs x86_64 4.11.3-40.el7 base 278 k rpm-python x86_64 4.11.3-40.el7 base 83 k yum noarch 3.4.3-163.el7.centos base 1.2 M事务概要============================================================================================================================================================================================================================升级 1 软件包 (+6 依赖软件包)总计:3.1 MDownloading packages:Running transaction checkRunning transaction testTransaction test succeededRunning transaction 正在更新 : rpm-libs-4.11.3-40.el7.x86_64 1/14 正在更新 : rpm-4.11.3-40.el7.x86_64 2/14 正在更新 : rpm-build-libs-4.11.3-40.el7.x86_64 3/14 正在更新 : rpm-python-4.11.3-40.el7.x86_64 4/14 正在更新 : python-urlgrabber-3.10-9.el7.noarch 5/14 正在更新 : yum-3.4.3-163.el7.centos.noarch 6/14 正在更新 : yum-utils-1.1.31-52.el7.noarch 7/14 清理 : yum-utils-1.1.31-24.el7.noarch 8/14 清理 : yum-3.4.3-118.el7.centos.noarch 9/14 清理 : rpm-python-4.11.1-16.el7.x86_64 10/14 清理 : python-urlgrabber-3.10-4.el7.noarch 11/14 清理 : rpm-build-libs-4.11.1-16.el7.x86_64 12/14 清理 : rpm-libs-4.11.1-16.el7.x86_64 13/14 清理 : rpm-4.11.1-16.el7.x86_64 14/14 验证中 : python-urlgrabber-3.10-9.el7.noarch 1/14 验证中 : rpm-python-4.11.3-40.el7.x86_64 2/14 验证中 : yum-utils-1.1.31-52.el7.noarch 3/14 验证中 : rpm-4.11.3-40.el7.x86_64 4/14 验证中 : yum-3.4.3-163.el7.centos.noarch 5/14 验证中 : rpm-libs-4.11.3-40.el7.x86_64 6/14 验证中 : rpm-build-libs-4.11.3-40.el7.x86_64 7/14 验证中 : python-urlgrabber-3.10-4.el7.noarch 8/14 验证中 : rpm-python-4.11.1-16.el7.x86_64 9/14 验证中 : rpm-build-libs-4.11.1-16.el7.x86_64 10/14 验证中 : rpm-libs-4.11.1-16.el7.x86_64 11/14 验证中 : yum-utils-1.1.31-24.el7.noarch 12/14 验证中 : yum-3.4.3-118.el7.centos.noarch 13/14 验证中 : rpm-4.11.1-16.el7.x86_64 14/14 更新完毕: yum-utils.noarch 0:1.1.31-52.el7 作为依赖被升级: python-urlgrabber.noarch 0:3.10-9.el7 rpm.x86_64 0:4.11.3-40.el7 rpm-build-libs.x86_64 0:4.11.3-40.el7 rpm-libs.x86_64 0:4.11.3-40.el7 rpm-python.x86_64 0:4.11.3-40.el7 yum.noarch 0:3.4.3-163.el7.centos 完毕!
添加下载地址:
yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo
安装最新版本的Docker Engine和容器,或转到下一步以安装特定版本: 过程比较漫长 等等就好
yum install docker-ce docker-ce-cli containerd.io
如果提示您接受GPG密钥,请验证指纹是否匹配 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35,如果是,则接受它。
不出意外 你会看到 成功两个字 ,
启动Docker。 systemctl start docker
别急 如果启动失败了 说明 版本问题导致的
你可以先卸载 再 继续安装 ,当然是选择性安装 根据版本号安装
要安装特定版本的Docker Engine,请在存储库中列出可用版本,然后选择并安装:
一个。列出并排序您存储库中可用的版本。此示例按版本号(从高到低)对结果进行排序,
[root@localhost lib]# yum list docker-ce --showduplicates | sort -r已加载插件:fastestmirror, langpacks可安装的软件包 * updates: mirrors.aliyun.comLoading mirror speeds from cached hostfile * extras: mirrors.aliyun.comdocker-ce.x86_64 3:19.03.8-3.el7 docker-ce-stabledocker-ce.x86_64 3:19.03.7-3.el7 docker-ce-stabledocker-ce.x86_64 3:19.03.6-3.el7 docker-ce-stabledocker-ce.x86_64 3:19.03.5-3.el7 docker-ce-stabledocker-ce.x86_64 3:19.03.4-3.el7 docker-ce-stabledocker-ce.x86_64 3:19.03.3-3.el7 docker-ce-stabledocker-ce.x86_64 3:19.03.2-3.el7 docker-ce-stabledocker-ce.x86_64 3:19.03.1-3.el7 docker-ce-stabledocker-ce.x86_64 3:19.03.0-3.el7 docker-ce-stabledocker-ce.x86_64 3:18.09.9-3.el7 docker-ce-stabledocker-ce.x86_64 3:18.09.8-3.el7 docker-ce-stabledocker-ce.x86_64 3:18.09.7-3.el7 docker-ce-stabledocker-ce.x86_64 3:18.09.6-3.el7 docker-ce-stabledocker-ce.x86_64 3:18.09.5-3.el7 docker-ce-stabledocker-ce.x86_64 3:18.09.4-3.el7 docker-ce-stabledocker-ce.x86_64 3:18.09.3-3.el7 docker-ce-stabledocker-ce.x86_64 3:18.09.2-3.el7 docker-ce-stabledocker-ce.x86_64 3:18.09.1-3.el7 docker-ce-stabledocker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stabledocker-ce.x86_64 18.06.3.ce-3.el7 docker-ce-stabledocker-ce.x86_64 18.06.2.ce-3.el7 docker-ce-stabledocker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stabledocker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stabledocker-ce.x86_64 18.03.1.ce-1.el7.centos docker-ce-stabledocker-ce.x86_64 18.03.0.ce-1.el7.centos docker-ce-stabledocker-ce.x86_64 17.12.1.ce-1.el7.centos docker-ce-stabledocker-ce.x86_64 17.12.0.ce-1.el7.centos docker-ce-stabledocker-ce.x86_64 17.09.1.ce-1.el7.centos docker-ce-stabledocker-ce.x86_64 17.09.0.ce-1.el7.centos docker-ce-stabledocker-ce.x86_64 17.06.2.ce-1.el7.centos docker-ce-stabledocker-ce.x86_64 17.06.1.ce-1.el7.centos docker-ce-stabledocker-ce.x86_64 17.06.0.ce-1.el7.centos docker-ce-stabledocker-ce.x86_64 17.03.3.ce-1.el7 docker-ce-stabledocker-ce.x86_64 17.03.2.ce-1.el7.centos docker-ce-stabledocker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stabledocker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable
返回的列表取决于启用了哪些存储库,并且特定于您的CentOS版本(.el7在本示例中以后缀表示)。b。通过其完全合格的软件包名称安装特定版本,该软件包名称是软件包名称(docker-ce)加上版本字符串(第二列),从第一个冒号(:)一直到第一个连字符,并用连字符(-)分隔。例如,docker-ce-18.09.1。yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io首先卸载之前的安装 (当然你也可以选择升级linux内核)yum remove docker-ce docker-ce-cli containerd.iorm -rf /var/lib/docker执行完成后继续下面的执行
[root@localhost ~]# yum install docker-ce-17.09.1.ceBDB2053 Freeing read locks for locker 0x72a: 51685/139945979692864已加载插件:fastestmirror, langpacksLoading mirror speeds from cached hostfile * base: mirror.lzu.edu.cn * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com正在解决依赖关系--> 正在检查事务---> 软件包 docker-ce.x86_64.0.17.09.1.ce-1.el7.centos 将被 安装--> 解决依赖关系完成依赖关系解决============================================================================================================================================================================================================================================================================= Package 架构 版本 源 大小=============================================================================================================================================================================================================================================================================正在安装: docker-ce x86_64 17.09.1.ce-1.el7.centos docker-ce-stable 21 M事务概要=============================================================================================================================================================================================================================================================================安装 1 软件包总下载量:21 M安装大小:21 MIs this ok [y/d/N]: yDownloading packages:docker-ce-17.09.1.ce-1.el7.cen FAILED 91% [==================================================================================================== ] 1.2 B/s | 19 MB 433:07:05 ETA https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-17.09.1.ce-1.el7.centos.x86_64.rpm: [Errno 12] Timeout on https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-17.09.1.ce-1.el7.centos.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')正在尝试其它镜像。docker-ce-17.09.1.ce-1.el7.centos.x86_64.rpm | 21 MB 00:00:56 Running transaction checkRunning transaction testTransaction test succeededRunning transaction 正在安装 : docker-ce-17.09.1.ce-1.el7.centos.x86_64 1/1 验证中 : docker-ce-17.09.1.ce-1.el7.centos.x86_64 1/1 已安装: docker-ce.x86_64 0:17.09.1.ce-1.el7.centos 完毕![root@localhost ~]# systemctl status docker.service ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled) Active: failed (Result: start-limit) since 二 2020-04-07 21:52:23 CST; 41min ago Docs: https://docs.docker.com Main PID: 51154 (code=exited, status=1/FAILURE)4月 07 21:52:21 localhost.localdomain systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE4月 07 21:52:21 localhost.localdomain systemd[1]: Failed to start Docker Application Container Engine.4月 07 21:52:21 localhost.localdomain systemd[1]: Unit docker.service entered failed state.4月 07 21:52:21 localhost.localdomain systemd[1]: docker.service failed.4月 07 21:52:23 localhost.localdomain systemd[1]: docker.service holdoff time over, scheduling restart.4月 07 21:52:23 localhost.localdomain systemd[1]: Stopped Docker Application Container Engine.4月 07 21:52:23 localhost.localdomain systemd[1]: start request repeated too quickly for docker.service4月 07 21:52:23 localhost.localdomain systemd[1]: Failed to start Docker Application Container Engine.4月 07 21:52:23 localhost.localdomain systemd[1]: Unit docker.service entered failed state.4月 07 21:52:23 localhost.localdomain systemd[1]: docker.service failed.[root@localhost ~]# systemctl start docker.service [root@localhost ~]# [root@localhost ~]# [root@localhost ~]# systemctl status docker.service ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled) Active: active (running) since 二 2020-04-07 22:33:51 CST; 8s ago Docs: https://docs.docker.com Main PID: 53799 (dockerd) Memory: 14.7M CGroup: /system.slice/docker.service ├─53799 /usr/bin/dockerd └─53805 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --shim docker-containerd-shim --runtime docker-runc4月 07 22:33:50 localhost.localdomain dockerd[53799]: time="2020-04-07T22:33:50.384733771+08:00" level=info msg="devmapper: Successfully created filesystem xfs on device docker-253:1-2180700-base"4月 07 22:33:50 localhost.localdomain dockerd[53799]: time="2020-04-07T22:33:50.460507062+08:00" level=info msg="Graph migration to content-addressability took 0.00 seconds"4月 07 22:33:50 localhost.localdomain dockerd[53799]: time="2020-04-07T22:33:50.460884311+08:00" level=warning msg="mountpoint for pids not found"4月 07 22:33:50 localhost.localdomain dockerd[53799]: time="2020-04-07T22:33:50.461183759+08:00" level=info msg="Loading containers: start."4月 07 22:33:50 localhost.localdomain dockerd[53799]: time="2020-04-07T22:33:50.901283597+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to set a preferred IP address"4月 07 22:33:51 localhost.localdomain dockerd[53799]: time="2020-04-07T22:33:51.123313352+08:00" level=info msg="Loading containers: done."4月 07 22:33:51 localhost.localdomain dockerd[53799]: time="2020-04-07T22:33:51.140985188+08:00" level=info msg="Docker daemon" commit=19e2cf6 graphdriver(s)=devicemapper version=17.09.1-ce4月 07 22:33:51 localhost.localdomain dockerd[53799]: time="2020-04-07T22:33:51.141114485+08:00" level=info msg="Daemon has completed initialization"4月 07 22:33:51 localhost.localdomain dockerd[53799]: time="2020-04-07T22:33:51.164127752+08:00" level=info msg="API listen on /var/run/docker.sock"4月 07 22:33:51 localhost.localdomain systemd[1]: Started Docker Application Container Engine.
然后运行示例程序 在这之前 需要引入国内的镜像地址
通过运行hello-world 映像来验证是否正确安装了Docker Engine 。
docker run hello-world
/etc/docker 目录下创建 daemon.json
[root@localhost docker]# ll总用量 8-rw-r--r-- 1 root root 65 4月 7 22:50 daemon.json-rw------- 1 root root 244 4月 7 22:33 key.json
然后里面的内容为
{ "registry-mirrors": ["https://alzgoonw.mirror.aliyuncs.com"] }
保存后 执行 测试命令
[root@localhost docker]# docker run hello-worldUnable 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 bashShare 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]# docker run hello-worldHello 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 bashShare 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]#
本文转自: https://blog.51cto.com/u_15446828/4775102
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70003733/viewspace-2847598/ ,如需转载,请注明出处,否则将追究法律责任。