-->

CentOS7 下Docker安装、启动

2021-02-20 02:17发布

↑点击上方“程序猿技术大咖”免费订阅
       最近在搞微服务,打算采用docker进行部署,便于环境迁移。本文就在CentOS 7下安装docker的过程,进行汇总整理,与大家进行分享,成功安装过程见2.2章节。

1、检查系统内核

      Docker 要求 CentOS 系统的内核版本高于 3.10 ,查看本页面的前提条件来验证你的CentOS 版本是否支持 Docker 。

通过 uname -r 命令查看你当前的内核版本。


   
   
   
  1. [xcbeyond@docker ~]$ uname -r

  2. 3.10.0-327.10.1.el7.x86_64

2、安装Docker

       安装过程及其坎坷,出现了各种问题,并进行记录整个过程,与大家进行分享。2.1 节记录安装过程中出现的各种问题,2.2节整理的是安装成功过程,作为正常安装步骤。

2.1 安装失败

(1)Docker 软件包和依赖包已经包含在默认的 CentOS-Extras 软件源里。执行命令yum install docker

安装过程如下:


   
   
   
  1. [xcbeyond@docker etc]$ sudo yum install docker

  2. Loaded plugins: fastestmirror, langpacks

  3. base                                                             | 3.6 kB  00:00:00

  4. docker-ce-stable                                                 | 2.9 kB  00:00:00

  5. extras                                                           | 3.4 kB  00:00:00

  6. updates                                                          | 3.4 kB  00:00:00

  7. docker-ce-stable/x86_64/primar FAILED

  8. https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/repodata/251ca0bf128072f68c0ccae90067d231841488501814e0b0b6f492c17c069daa-primary.sqlite.bz2: [Errno 14] curl#60 - "Peer's Certificate issuer is not recognized."

  9. Trying other mirror.

  10. It was impossible to connect to the CentOS servers.

  11. This could mean a connectivity issue in your environment, such as the requirement to configure a proxy,

  12. or a transparent proxy that tampers with TLS security, or an incorrect system clock.

  13. You can try to solve this issue by using the instructions on https://wiki.centos.org/yum-errors

  14. If above article doesn't help to resolve this issue please use https://bugs.centos.org/.


  15. Loading mirror speeds from cached hostfile

  16. * base: mirrors.nwsuaf.edu.cn

  17. * extras: mirror.lzu.edu.cn

  18. * updates: mirrors.163.com

  19. docker-ce-stable/x86_64/primar FAILED

  20. https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/repodata/251ca0bf128072f68c0ccae90067d231841488501814e0b0b6f492c17c069daa-primary.sqlite.bz2: [Errno 14] curl#60 - "Peer's Certificate issuer is not recognized."

  21. Trying other mirror.

  22. docker-ce-stable/x86_64/primary_db                               |  15 kB  00:00:00

  23. Resolving Dependencies

  24.                   ………………


  25. Transaction Summary

  26. ========================================================================================

  27. Install  1 Package (+12 Dependent packages)

  28. Upgrade  1 Package (+15 Dependent packages)


  29. Total download size: 38 M

  30. Is this ok [y/d/N]: y

  31. Downloading packages:

  32. No Presto metadata available for base

  33. updates/7/x86_64/prestodelta                                     | 538 kB  00:00:00

  34. (1/29): atomic-registries-1.22.1-22.git5a342e3.el7.x86_64.rpm    |  35 kB  00:00:00

  35. (2/29): container-selinux-2.68-1.el7.noarch.rpm                  |  36 kB  00:00:00

  36. (3/29): docker-common-1.13.1-74.git6e3bb8e.el7.centos.x86_64.rpm |  92 kB  00:00:00

  37. (4/29): container-storage-setup-0.11.0-2.git5eaf76c.el7.noarch.r |  35 kB  00:00:00

  38. (5/29): libselinux-2.5-12.el7.x86_64.rpm                         | 162 kB  00:00:00

  39. (6/29): libselinux-utils-2.5-12.el7.x86_64.rpm                   | 151 kB  00:00:00

  40. (7/29): libselinux-python-2.5-12.el7.x86_64.rpm                  | 235 kB  00:00:00

  41. (8/29): libsemanage-2.5-11.el7.x86_64.rpm                        | 150 kB  00:00:00

  42.                     ………………

  43. (29/29): docker-1.13.1-74.git6e3bb8e.el7.centos.x86_64.rpm       |  16 MB  00:00:09

  44. ----------------------------------------------------------------------------------------

  45. Total                                                      3.9 MB/s |  38 MB  00:09

  46. Running transaction check

  47. Running transaction test

  48. Transaction test succeeded

  49. Running transaction

  50. Updating   : libsepol-2.5-8.1.el7.x86_64                                         1/45

  51. Updating   : libselinux-2.5-12.el7.x86_64                                        2/45

  52. Updating   : libsemanage-2.5-11.el7.x86_64                                       3/45

  53. Installing : lz4-1.7.5-2.el7.x86_64                                              4/45

  54. Updating   : systemd-libs-219-57.el7_5.1.x86_64                                  5/45

  55. Updating   : systemd-219-57.el7_5.1.x86_64                                       6/45

  56. Updating   : libselinux-utils-2.5-12.el7.x86_64                                  7/45

  57. Updating   : policycoreutils-2.5-22.el7.x86_64                                   8/45

  58. Updating   : selinux-policy-3.13.1-192.el7_5.6.noarch                            9/45

  59. Updating   : selinux-policy-targeted-3.13.1-192.el7_5.6.noarch                  10/45

  60. warning: /etc/selinux/targeted/seusers created as /etc/selinux/targeted/seusers.rpmnew

  61. ‘/etc/selinux/targeted/modules/active/seusers’ -> ‘/etc/selinux/targeted/active/seusers.local’

  62. Installing : 1:oci-register-machine-0-6.git2b44233.el7.x86_64                   11/45

  63. Updating   : libsemanage-python-2.5-11.el7.x86_64                               12/45

  64. Updating   : libselinux-python-2.5-12.el7.x86_64                                13/45

  65. Installing : 1:oci-systemd-hook-0.1.17-2.git83283a0.el7.x86_64                  14/45

  66. Installing : 2:oci-umount-2.3.3-3.gite3c9055.el7.x86_64                         15/45

  67. Updating   : setools-libs-3.3.8-2.el7.x86_64                                    16/45

  68. Updating   : policycoreutils-python-2.5-22.el7.x86_64                           17/45

  69. Installing : 2:container-selinux-2.68-1.el7.noarch                              18/45

  70. Installing : container-storage-setup-0.11.0-2.git5eaf76c.el7.noarch             19/45

  71. Installing : python-pytoml-0.1.14-1.git7dea353.el7.noarch                       20/45

  72. Installing : 1:atomic-registries-1.22.1-22.git5a342e3.el7.x86_64                21/45

  73. Installing : 1:skopeo-containers-0.1.31-1.dev.gitae64ff7.el7.centos.x86_64      22/45

  74. Installing : 2:docker-common-1.13.1-74.git6e3bb8e.el7.centos.x86_64             23/45

  75. Installing : 2:docker-client-1.13.1-74.git6e3bb8e.el7.centos.x86_64             24/45

  76. Installing : subscription-manager-rhsm-certificates-1.20.11-1.el7.centos.x86_   25/45

  77. Installing : 2:docker-1.13.1-74.git6e3bb8e.el7.centos.x86_64                    26/45

  78. Updating   : systemd-python-219-57.el7_5.1.x86_64                               27/45

  79. Updating   : systemd-sysv-219-57.el7_5.1.x86_64                                 28/45

  80. Updating   : libgudev1-219-57.el7_5.1.x86_64                                    29/45

  81. Cleanup    : policycoreutils-python-2.2.5-20.el7.x86_64                         30/45

  82. Cleanup    : selinux-policy-targeted-3.13.1-60.el7_2.3.noarch                   31/45

  83. warning: /etc/selinux/targeted/modules/active/seusers.final saved as /etc/selinux/targeted/modules/active/seusers.final.rpmsave

  84. Cleanup    : systemd-python-219-19.el7_2.4.x86_64                               32/45

  85. Cleanup    : selinux-policy-3.13.1-60.el7_2.3.noarch                            33/45

  86. Cleanup    : systemd-sysv-219-19.el7_2.4.x86_64                                 34/45

  87. Cleanup    : policycoreutils-2.2.5-20.el7.x86_64                                35/45

  88. Cleanup    : systemd-219-19.el7_2.4.x86_64                                      36/45

  89. Cleanup    : setools-libs-3.3.7-46.el7.x86_64                                   37/45

  90. Cleanup    : libselinux-utils-2.2.2-6.el7.x86_64                                38/45

  91. Cleanup    : libselinux-python-2.2.2-6.el7.x86_64                               39/45

  92. Cleanup    : libsemanage-python-2.1.10-18.el7.x86_64                            40/45

  93. Cleanup    : libsemanage-2.1.10-18.el7.x86_64                                   41/45

  94. Cleanup    : libgudev1-219-19.el7_2.4.x86_64                                    42/45

  95. Cleanup    : systemd-libs-219-19.el7_2.4.x86_64                                 43/45

  96. Cleanup    : libselinux-2.2.2-6.el7.x86_64                                      44/45

  97. Cleanup    : libsepol-2.1.9-3.el7.x86_64                                        45/45

  98. Verifying  : libsemanage-python-2.5-11.el7.x86_64                                1/45

  99. Verifying  : libsemanage-2.5-11.el7.x86_64                                       2/45

  100. Verifying  : libselinux-python-2.5-12.el7.x86_64                                 3/45

  101. Verifying  : subscription-manager-rhsm-certificates-1.20.11-1.el7.centos.x86_    4/45

  102. Verifying  : 2:container-selinux-2.68-1.el7.noarch                               5/45

  103. Verifying  : libselinux-utils-2.5-12.el7.x86_64                                  6/45

  104. Verifying  : policycoreutils-2.5-22.el7.x86_64                                   7/45

  105. Verifying  : libsepol-2.5-8.1.el7.x86_64                                         8/45

  106. Verifying  : 1:skopeo-containers-0.1.31-1.dev.gitae64ff7.el7.centos.x86_64       9/45

  107. Verifying  : policycoreutils-python-2.5-22.el7.x86_64                           10/45

  108. Verifying  : 1:oci-systemd-hook-0.1.17-2.git83283a0.el7.x86_64                  11/45

  109. Verifying  : selinux-policy-targeted-3.13.1-192.el7_5.6.noarch                  12/45

  110. Verifying  : python-pytoml-0.1.14-1.git7dea353.el7.noarch                       13/45

  111. Verifying  : systemd-python-219-57.el7_5.1.x86_64                               14/45

  112. Verifying  : systemd-219-57.el7_5.1.x86_64                                      15/45

  113. Verifying  : libgudev1-219-57.el7_5.1.x86_64                                    16/45

  114. Verifying  : 2:docker-common-1.13.1-74.git6e3bb8e.el7.centos.x86_64             17/45

  115. Verifying  : systemd-libs-219-57.el7_5.1.x86_64                                 18/45

  116. Verifying  : lz4-1.7.5-2.el7.x86_64                                             19/45

  117. Verifying  : 1:oci-register-machine-0-6.git2b44233.el7.x86_64                   20/45

  118. Verifying  : 2:oci-umount-2.3.3-3.gite3c9055.el7.x86_64                         21/45

  119. Verifying  : 2:docker-client-1.13.1-74.git6e3bb8e.el7.centos.x86_64             22/45

  120. Verifying  : 2:docker-1.13.1-74.git6e3bb8e.el7.centos.x86_64                    23/45

  121. Verifying  : systemd-sysv-219-57.el7_5.1.x86_64                                 24/45

  122. Verifying  : setools-libs-3.3.8-2.el7.x86_64                                    25/45

  123. Verifying  : libselinux-2.5-12.el7.x86_64                                       26/45

  124. Verifying  : 1:atomic-registries-1.22.1-22.git5a342e3.el7.x86_64                27/45

  125. Verifying  : container-storage-setup-0.11.0-2.git5eaf76c.el7.noarch             28/45

  126. Verifying  : selinux-policy-3.13.1-192.el7_5.6.noarch                           29/45

  127. Verifying  : systemd-python-219-19.el7_2.4.x86_64                               30/45

  128. Verifying  : selinux-policy-targeted-3.13.1-60.el7_2.3.noarch                   31/45

  129. Verifying  : libsemanage-python-2.1.10-18.el7.x86_64                            32/45

  130. Verifying  : setools-libs-3.3.7-46.el7.x86_64                                   33/45

  131. Verifying  : libsemanage-2.1.10-18.el7.x86_64                                   34/45

  132. Verifying  : systemd-219-19.el7_2.4.x86_64                                      35/45

  133. Verifying  : systemd-sysv-219-19.el7_2.4.x86_64                                 36/45

  134. Verifying  : libselinux-utils-2.2.2-6.el7.x86_64                                37/45

  135. Verifying  : systemd-libs-219-19.el7_2.4.x86_64                                 38/45

  136. Verifying  : selinux-policy-3.13.1-60.el7_2.3.noarch                            39/45

  137. Verifying  : libsepol-2.1.9-3.el7.x86_64                                        40/45

  138. Verifying  : libgudev1-219-19.el7_2.4.x86_64                                    41/45

  139. Verifying  : libselinux-python-2.2.2-6.el7.x86_64                               42/45

  140. Verifying  : policycoreutils-2.2.5-20.el7.x86_64                                43/45

  141. Verifying  : libselinux-2.2.2-6.el7.x86_64                                      44/45

  142. Verifying  : policycoreutils-python-2.2.5-20.el7.x86_64                         45/45


  143. Installed:

  144. docker.x86_64 2:1.13.1-74.git6e3bb8e.el7.centos


  145. Dependency Installed:

  146. atomic-registries.x86_64 1:1.22.1-22.git5a342e3.el7

  147. container-selinux.noarch 2:2.68-1.el7

  148. container-storage-setup.noarch 0:0.11.0-2.git5eaf76c.el7

  149. docker-client.x86_64 2:1.13.1-74.git6e3bb8e.el7.centos

  150. docker-common.x86_64 2:1.13.1-74.git6e3bb8e.el7.centos

  151. lz4.x86_64 0:1.7.5-2.el7

  152. oci-register-machine.x86_64 1:0-6.git2b44233.el7

  153. oci-systemd-hook.x86_64 1:0.1.17-2.git83283a0.el7

  154. oci-umount.x86_64 2:2.3.3-3.gite3c9055.el7

  155. python-pytoml.noarch 0:0.1.14-1.git7dea353.el7

  156. skopeo-containers.x86_64 1:0.1.31-1.dev.gitae64ff7.el7.centos

  157. subscription-manager-rhsm-certificates.x86_64 0:1.20.11-1.el7.centos


  158. Updated:

  159. systemd.x86_64 0:219-57.el7_5.1


  160. Dependency Updated:

  161. libgudev1.x86_64 0:219-57.el7_5.1

  162. libselinux.x86_64 0:2.5-12.el7

  163. libselinux-python.x86_64 0:2.5-12.el7

  164. libselinux-utils.x86_64 0:2.5-12.el7

  165. libsemanage.x86_64 0:2.5-11.el7

  166. libsemanage-python.x86_64 0:2.5-11.el7

  167. libsepol.x86_64 0:2.5-8.1.el7

  168. policycoreutils.x86_64 0:2.5-22.el7

  169. policycoreutils-python.x86_64 0:2.5-22.el7

  170. selinux-policy.noarch 0:3.13.1-192.el7_5.6

  171. selinux-policy-targeted.noarch 0:3.13.1-192.el7_5.6

  172. setools-libs.x86_64 0:3.3.8-2.el7

  173. systemd-libs.x86_64 0:219-57.el7_5.1

  174. systemd-python.x86_64 0:219-57.el7_5.1

  175. systemd-sysv.x86_64 0:219-57.el7_5.1


  176. Complete!

(2)查看Docker版本。执行命令docker version


   
   
   
  1. [xcbeyond@docker etc]$ docker version

  2. Client:

  3. Version:         1.13.1

  4. API version:     1.26

  5. Package version:

  6. Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

(3)启动Docker。执行命令 service docker start.


   
   
   
  1. [xcbeyond@docker ~]$ sudo service docker start

  2. Redirecting to /bin/systemctl start  docker.service

  3. Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.

哎,启动失败了。查看下docker状态,如下所示:


   
   
   
  1. [xcbeyond@docker ~]$ systemctl status docker

  2. ● docker.service - Docker Application Container Engine

  3. Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)

  4. Active: failed (Result: exit-code) since Wed 2018-08-29 23:07:19 CST; 1min 13s ago

  5. Docs: http://docs.docker.com

  6. Process: 18527 ExecStart=/usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-path=/usr/libexec/docker/docker-proxy-current --init-path=/usr/libexec/docker/docker-init-current --seccomp-profile=/etc/docker/seccomp.json $OPTIONS $DOCKER_STORAGE_OPTIONS $DOCKER_NETWORK_OPTIONS $ADD_REGISTRY $BLOCK_REGISTRY $INSECURE_REGISTRY $REGISTRIES (code=exited, status=1/FAILURE)

  7. Main PID: 18527 (code=exited, status=1/FAILURE)


  8. Aug 29 23:07:17 docker systemd[1]: Starting Docker Application Container Engine...

  9. Aug 29 23:07:18 docker dockerd-current[18527]: time="2018-08-29T23:07:18.066916004+...d"

  10. Aug 29 23:07:18 docker dockerd-current[18527]: time="2018-08-29T23:07:18.071982389+...1"

  11. Aug 29 23:07:19 docker dockerd-current[18527]: time="2018-08-29T23:07:19.085154395+08...

  12. Aug 29 23:07:19 docker dockerd-current[18527]: Error starting daemon: SELinux is no...e)

  13. Aug 29 23:07:19 docker systemd[1]: docker.service: main process exited, code=exite...URE

  14. Aug 29 23:07:19 docker systemd[1]: Failed to start Docker Application Container Engine.

  15. Aug 29 23:07:19 docker systemd[1]: Unit docker.service entered failed state.

  16. Aug 29 23:07:19 docker systemd[1]: docker.service failed.

  17. Hint: Some lines were ellipsized, use -l to show in full.

网上查阅了大量资料,进行配置的修改等,尝试都未能解决,最终决定还是卸载掉,重新换种方式来安装吧。

2.2 安装成功

(1)卸载docker,并配置docker.repo,如下所示:


   
   
   
  1. [xcbeyond@docker run]$ sudo yum remove docker

  2. ……

  3. [xcbeyond@docker run]$ sudo yum remove docker-selinux

  4. ……

  5. [xcbeyond@docker run]$ sudo vi /etc/yum.repos.d/docker.repo

  6. [dockerrepo]

  7. name=Docker Repository

  8. baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/

  9. enabled=1

  10. gpgcheck=1

  11. gpgkey=https://yum.dockerproject.org/gpg

(2)安装docker,执行命令yum install docker-engine,如下所示:

(如失败,则可多执行几次便可。安装过程,因需下载安装包,请耐心等待)


   
   
   
  1. [xcbeyond@docker run]$ sudo yum install docker-engine

  2. Loaded plugins: fastestmirror, langpacks

  3. base                                                             | 3.6 kB  00:00:00    

  4. dockerrepo                                                       | 2.9 kB  00:00:00    

  5. extras                                                           | 3.4 kB  00:00:00    

  6. updates                                                          | 3.4 kB  00:00:00    

  7. Loading mirror speeds from cached hostfile

  8. * base: mirror.lzu.edu.cn

  9. * extras: mirrors.aliyun.com

  10. * updates: mirrors.aliyun.com

  11. Resolving Dependencies

  12. --> Running transaction check

  13. ---> Package docker-engine.x86_64 0:17.05.0.ce-1.el7.centos will be installed

  14. --> Processing Dependency: docker-engine-selinux >= 17.05.0.ce-1.el7.centos for package: docker-engine-17.05.0.ce-1.el7.centos.x86_64

  15. --> Running transaction check

  16. ---> Package docker-engine-selinux.noarch 0:17.05.0.ce-1.el7.centos will be installed

  17. --> Finished Dependency Resolution


  18. Dependencies Resolved


  19. ========================================================================================

  20. Package                   Arch       Version                      Repository      Size

  21. ========================================================================================

  22. Installing:

  23. docker-engine             x86_64     17.05.0.ce-1.el7.centos      dockerrepo      19 M

  24. Installing for dependencies:

  25. docker-engine-selinux     noarch     17.05.0.ce-1.el7.centos      dockerrepo      28

标签: