CentOS Docker 安装

红太狼 2020-11-29 15:31 1035阅读 0赞

CentOS Docker 安装

Docker是一个开放源代码软件项目,让应用程序布署在软件容器下的工作可以自动化进行,借此在Linux操作系统上,提供一个额外的软件抽象层,以及操作系统层虚拟化的自动管理机制。Docker利用Linux核心中的资源分脱机制,例如cgroups,以及Linux核心名字空间(name space),来创建独立的软件容器(containers)。这可以在单一Linux实体下运作,避免引导一个虚拟机造成的额外负担。Linux核心对名字空间的支持完全隔离了工作环境中应用程序的视野,包括进程树、网络、用户ID与挂载文件系统,而核心的cgroup提供资源隔离,包括CPU、内存、block I/O与网络


前提

本教程适用于CentOS 7 上,要求系统为64位、系统内核版本为 3.10 以上

方法一

1、更新yum源

  1. yum update -y

2、添加docker的yum源

  1. vi /etc/yum.repos.d/docker.repo
  2. [dockerrepo]
  3. name=Docker Repository
  4. baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/
  5. enabled=1
  6. gpgcheck=1
  7. gpgkey=https://yum.dockerproject.org/gpg

3、安装docker

  1. yum install docker-engine -y

4、设置为系统开机自动启动服务

  1. systemctl enable docker.service

5、启动服务

  1. systemctl start docker

方法二

1、安装依赖

  1. yum install yum-utils device-mapper-persistent-data lvm2 -y

2、配置源

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

以上命令会添加稳定版本的 docker ce yum 源,从 docker 17.06 开始,edge test 版本的 yum 源也会包含稳定版本的 docker ce

  • 如果需要最新版本的 Docker CE 请使用以下命令,默认不启用(可不选)

    yum-config-manager —enable docker-ce-edge
    yum-config-manager —enable docker-ce-test

  • 如果想关闭edge和test的repository,可以执行下面的命令(可不选)

    yum-config-manager —disable docker-ce-edge
    yum-config-manager —disable docker-ce-test

3、安装

  • 默认版本安装

    yum install docker-ce -y

  • 指定版本安装

在生产系统上,您应该安装特定版本的docker,而不是始终使用最新版本

  1. # 列出 Docker 的版本
  2. yum list docker-ce --showduplicates|sort -r
  3. # 安装指定的版本
  4. # yum install docker-ce-<VERSION>
  5. yum install docker-ce-18.03.1.ce -y

4、查看进程

  1. systemctl list-unit-files|grep docker

5、开机自启

  1. systemctl enable docker

6、启动服务

  1. systemctl start docker

使用DaoCloud加速器获取Docker官方镜像

https://www.daocloud.io/mirror\#accelerator-doc

因为docker默认镜像是国外,下载速度可能会比较慢,如果需要登录请先注册,然后再点击,获取加速器代码

重启Docker

  1. systemctl restart docker

验证Docker是否安装成功并在容器中执行一个测试的镜像

  1. docker run hello-world

输出以下信息

  1. [root@service ~]# docker run hello-world
  2. Hello from Docker!
  3. This message shows that your installation appears to be working correctly.
  4. To generate this message, Docker took the following steps:
  5. 1. The Docker client contacted the Docker daemon.
  6. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
  7. (amd64)
  8. 3. The Docker daemon created a new container from that image which runs the
  9. executable that produces the output you are currently reading.
  10. 4. The Docker daemon streamed that output to the Docker client, which sent it
  11. to your terminal.
  12. To try something more ambitious, you can run an Ubuntu container with:
  13. $ docker run -it ubuntu bash
  14. Share images, automate workflows, and more with a free Docker ID:
  15. https://cloud.docker.com/
  16. For more examples and ideas, visit:
  17. https://docs.docker.com/engine/userguide/

至此,我们已成功安装并运行起Docker容器


附:

安装docker-ce-17.03.2.ce版本时问题

(1)

  1. [root@service ~]# yum install docker-ce-17.03.2.ce
  2. Loaded plugins: fastestmirror
  3. Loading mirror speeds from cached hostfile
  4. Resolving Dependencies
  5. --> Running transaction check
  6. ---> Package docker-ce.x86_64 0:17.03.2.ce-1.el7.centos will be installed
  7. --> Processing Dependency: docker-ce-selinux >= 17.03.2.ce-1.el7.centos for package: docker-ce-17.03.2.ce-1.el7.centos.x86_64
  8. Package docker-ce-selinux is obsoleted by docker-ce, but obsoleting package does not provide for requirements
  9. --> Processing Dependency: libcgroup for package: docker-ce-17.03.2.ce-1.el7.centos.x86_64
  10. --> Processing Dependency: libltdl.so.7()(64bit) for package: docker-ce-17.03.2.ce-1.el7.centos.x86_64
  11. --> Running transaction check
  12. ---> Package docker-ce.x86_64 0:17.03.2.ce-1.el7.centos will be installed
  13. --> Processing Dependency: docker-ce-selinux >= 17.03.2.ce-1.el7.centos for package: docker-ce-17.03.2.ce-1.el7.centos.x86_64
  14. Package docker-ce-selinux is obsoleted by docker-ce, but obsoleting package does not provide for requirements
  15. ---> Package libcgroup.x86_64 0:0.41-15.el7 will be installed
  16. ---> Package libtool-ltdl.x86_64 0:2.4.2-22.el7_3 will be installed
  17. --> Finished Dependency Resolution
  18. Error: Package: docker-ce-17.03.2.ce-1.el7.centos.x86_64 (docker-ce-stable)
  19. Requires: docker-ce-selinux >= 17.03.2.ce-1.el7.centos
  20. Available: docker-ce-selinux-17.03.0.ce-1.el7.centos.noarch (docker-ce-stable)
  21. docker-ce-selinux = 17.03.0.ce-1.el7.centos
  22. Available: docker-ce-selinux-17.03.1.ce-1.el7.centos.noarch (docker-ce-stable)
  23. docker-ce-selinux = 17.03.1.ce-1.el7.centos
  24. Available: docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch (docker-ce-stable)
  25. docker-ce-selinux = 17.03.2.ce-1.el7.centos
  26. Available: docker-ce-selinux-17.03.3.ce-1.el7.noarch (docker-ce-stable)
  27. docker-ce-selinux = 17.03.3.ce-1.el7
  28. You could try using --skip-broken to work around the problem
  29. You could try running: rpm -Va --nofiles --nodigest

解决办法:

要先安装docker-ce-selinux-17.03.2.ce,再安装docker-ce-17.03.2.ce

  1. yum install https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch.rpm

(2)

  1. [root@service ~]# yum install docker-ce-17.03.2.ce -y
  2. Loaded plugins: fastestmirror
  3. Loading mirror speeds from cached hostfile
  4. Resolving Dependencies
  5. --> Running transaction check
  6. ---> Package docker-ce.x86_64 0:17.03.2.ce-1.el7.centos will be installed
  7. --> Processing Dependency: libltdl.so.7()(64bit) for package: docker-ce-17.03.2.ce-1.el7.centos.x86_64
  8. --> Running transaction check
  9. ---> Package libtool-ltdl.x86_64 0:2.4.2-22.el7_3 will be installed
  10. --> Finished Dependency Resolution
  11. Dependencies Resolved
  12. =========================================================================================================================================================================================================================================
  13. Package Arch Version Repository Size
  14. =========================================================================================================================================================================================================================================
  15. Installing:
  16. docker-ce x86_64 17.03.2.ce-1.el7.centos docker-ce-stable 19 M
  17. Installing for dependencies:
  18. libtool-ltdl x86_64 2.4.2-22.el7_3 base 49 k
  19. Transaction Summary
  20. =========================================================================================================================================================================================================================================
  21. Install 1 Package (+1 Dependent package)
  22. Total size: 19 M
  23. Total download size: 19 M
  24. Installed size: 19 M
  25. Downloading packages:
  26. Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
  27. docker-ce-17.03.2.ce-1.el7.cen FAILED
  28. https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-17.03.2.ce-1.el7.centos.x86_64.rpm: [Errno 14] curl#6 - "Could not resolve host: download.docker.com; Unknown error" ] 0.0 B/s | 0 B --:--:-- ETA
  29. Trying other mirror.
  30. Error downloading packages:
  31. docker-ce-17.03.2.ce-1.el7.centos.x86_64: [Errno 256] No more mirrors to try.

docker-ce-17.03.2.ce-1.el7.centos.x86_64这个rpm包下载不下来,所以只能手动下载安装了

  1. # 下载docker-ce-17.03.2.ce-1.el7.centos.x86_64 rpm包
  2. wget --no-check-certificate https://cdn.ryana.cn/docker/docker-ce-17.03.2.ce-1.el7.centos.x86_64.rpm
  3. # 安装
  4. yum install docker-ce-17.03.2.ce-1.el7.centos.x86_64.rpm

发表评论

表情:
评论列表 (有 0 条评论,1035人围观)

还没有评论,来说两句吧...

相关阅读

    相关 CentOS Docker 安装

    使用 yum 安装(CentOS 7下) Docker 要求 CentOS 系统的内核版本高于 3.10 ,查看本页面的前提条件来验证你的CentOS 版本是否支持 Do

    相关 CentOS Docker 安装

    系统要求 Docker CE 支持 64 位版本 CentOS 7,并且要求内核版本不低于 3.10。 CentOS 7 满足最低内核的要求,但由于内核版本比较低,部分功

    相关 CentOS Docker 安装

    Docker是一个开放源代码软件项目,让应用程序布署在软件容器下的工作可以自动化进行,借此在Linux操作系统上,提供一个额外的软件抽象层,以及操作系统层虚拟化的自动管理...