CentOS7.4下搭建docker环境

版权声明:本文为junehappylove原创文章,未经junehappylove允许不得转载。 https://blog.csdn.net/junehappylove/article/details/82669476

Docker从1.13版本之后采用时间线的方式作为版本号,分为社区版CE和企业版EE。
社区版是免费提供给个人开发者和小型团体使用的,企业版会提供额外的收费服务,比如经过官方测试认证过的基础设施、容器、插件等。
社区版按照stable和edge两种方式发布,每个季度更新stable版本,如18.03,18.06;每个月份更新edge版本,如18.06,18.07。

Docker安装

  • Docker 要求 CentOS 系统的内核版本高于 3.10 ,查看本页面的前提条件来验证你的CentOS 版本是否支持 Docker 。
    通过 uname -r 命令查看你当前的内核版本
[root@ecs-a30e-0002 ~]# uname -r
3.10.0-693.11.1.el7.x86_64
  • 使用 root 权限登录 Centos。确保 yum 包更新到最新。
[root@ecs-a30e-0002 ~]# yum update
  • 卸载旧版本(如果安装过旧版本的话)
[root@ecs-a30e-0002 ~]# yum remove docker  docker-common docker-selinux docker-engine
  • 安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的
[root@ecs-a30e-0002 ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
  • 设置docker的yum源
[root@ecs-a30e-0002 ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
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
  • 可以查看所有仓库中所有docker版本,并选择特定版本安装
[root@ecs-a30e-0002 ~]# yum list docker-ce --showduplicates | sort -r
 * updates: mirror.bit.edu.cn
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror
 * extras: mirrors.huaweicloud.com
 * epel: mirrors.huaweicloud.com
docker-ce.x86_64            18.06.1.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.06.0.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.03.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            18.03.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.12.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.12.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.09.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.09.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.2.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.3.ce-1.el7                    docker-ce-stable
docker-ce.x86_64            17.03.2.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.0.ce-1.el7.centos             docker-ce-stable
 * base: mirror.bit.edu.cn
Available Packages
  • 安装docker
$ sudo yum install docker-ce  #由于repo中默认只开启stable仓库,故这里安装的是最新稳定版17.12.0


[root@ecs-a30e-0002 ~]# yum install docker-ce
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.bit.edu.cn
 * epel: mirrors.huaweicloud.com
 * extras: mirrors.huaweicloud.com
 * updates: mirror.bit.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 0:18.06.1.ce-3.el7 will be installed
--> Processing Dependency: container-selinux >= 2.9 for package: docker-ce-18.06.1.ce-3.el7.x86_64
--> Processing Dependency: libseccomp >= 2.3 for package: docker-ce-18.06.1.ce-3.el7.x86_64
--> Processing Dependency: libseccomp.so.2()(64bit) for package: docker-ce-18.06.1.ce-3.el7.x86_64
--> Processing Dependency: libltdl.so.7()(64bit) for package: docker-ce-18.06.1.ce-3.el7.x86_64
--> Running transaction check
---> Package container-selinux.noarch 2:2.68-1.el7 will be installed
---> Package libseccomp.x86_64 0:2.3.1-3.el7 will be installed
---> Package libtool-ltdl.x86_64 0:2.4.2-22.el7_3 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================================================================
 Package                                   Arch                           Version                                    Repository                                Size
====================================================================================================================================================================
Installing:
 docker-ce                                 x86_64                         18.06.1.ce-3.el7                           docker-ce-stable                          41 M
Installing for dependencies:
 container-selinux                         noarch                         2:2.68-1.el7                               extras                                    36 k
 libseccomp                                x86_64                         2.3.1-3.el7                                base                                      56 k
 libtool-ltdl                              x86_64                         2.4.2-22.el7_3                             base                                      49 k

Transaction Summary
====================================================================================================================================================================
Install  1 Package (+3 Dependent packages)

Total download size: 41 M
Installed size: 41 M
Is this ok [y/d/N]: y
Downloading packages:
(1/4): container-selinux-2.68-1.el7.noarch.rpm                                                                                               |  36 kB  00:00:00     
(2/4): libtool-ltdl-2.4.2-22.el7_3.x86_64.rpm                                                                                                |  49 kB  00:00:00     
(3/4): libseccomp-2.3.1-3.el7.x86_64.rpm                                                                                                     |  56 kB  00:00:00     
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-18.06.1.ce-3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY0:00:00 ETA 
Public key for docker-ce-18.06.1.ce-3.el7.x86_64.rpm is not installed
(4/4): docker-ce-18.06.1.ce-3.el7.x86_64.rpm                                                                                                 |  41 MB  00:13:30     
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                52 kB/s |  41 MB  00:13:30     
Retrieving key from https://download.docker.com/linux/centos/gpg
Importing GPG key 0x621E9F35:
 Userid     : "Docker Release (CE rpm) <[email protected]>"
 Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
 From       : https://download.docker.com/linux/centos/gpg
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libseccomp-2.3.1-3.el7.x86_64                                                                                                                    1/4 
  Installing : 2:container-selinux-2.68-1.el7.noarch                                                                                                            2/4 
setsebool:  SELinux is disabled.
  Installing : libtool-ltdl-2.4.2-22.el7_3.x86_64                                                                                                               3/4 
  Installing : docker-ce-18.06.1.ce-3.el7.x86_64                                                                                                                4/4 
  Verifying  : docker-ce-18.06.1.ce-3.el7.x86_64                                                                                                                1/4 
  Verifying  : libtool-ltdl-2.4.2-22.el7_3.x86_64                                                                                                               2/4 
  Verifying  : 2:container-selinux-2.68-1.el7.noarch                                                                                                            3/4 
  Verifying  : libseccomp-2.3.1-3.el7.x86_64                                                                                                                    4/4 

Installed:
  docker-ce.x86_64 0:18.06.1.ce-3.el7                                                                                                                               

Dependency Installed:
  container-selinux.noarch 2:2.68-1.el7                   libseccomp.x86_64 0:2.3.1-3.el7                   libtool-ltdl.x86_64 0:2.4.2-22.el7_3                  

Complete!
  • 启动并加入开机启动
[root@ecs-a30e-0002 ~]# systemctl start docker
[root@ecs-a30e-0002 ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
  • 验证安装是否成功(有client和service两部分表示docker安装启动都成功了)
[root@ecs-a30e-0002 ~]# docker version
Client:
 Version:           18.06.1-ce
 API version:       1.38
 Go version:        go1.10.3
 Git commit:        e68fc7a
 Built:             Tue Aug 21 17:23:03 2018
 OS/Arch:           linux/amd64
 Experimental:      false

Server:
 Engine:
  Version:          18.06.1-ce
  API version:      1.38 (minimum version 1.12)
  Go version:       go1.10.3
  Git commit:       e68fc7a
  Built:            Tue Aug 21 17:25:29 2018
  OS/Arch:          linux/amd64
  Experimental:     false

所有安装方法参考自这里,我是边安装边记录

猜你喜欢

转载自blog.csdn.net/junehappylove/article/details/82669476