Centos7上安装docker
改编自:https://www.cnblogs.com/yufeng218/p/8370670.html
Docker从1.13版本之后采用时间线的方式作为版本号,分为社区版CE和企业版EE。
社区版是免费提供给个人开发者和小型团体使用的,企业版会提供额外的收费服务,比如经过官方测试认证过的基础设施、容器、插件等。
社区版按照stable和edge两种方式发布,每个季度更新stable版本,如17.06,17.09;每个月份更新edge版本,如17.09,17.10。
一、安装docker
1、Docker 要求 CentOS 系统的内核版本高于 3.10 ,查看本页面的前提条件来验证你的CentOS 版本是否支持 Docker 。
通过 uname -r 命令查看你当前的内核版本
$ uname -r
[[email protected] ~]# uname -r 3.10.0-693.el7.x86_64
2、使用 root 权限登录 Centos。确保 yum 包更新到最新。
$ sudo yum update
(代码不贴了)
3、卸载旧版本(如果安装过旧版本的话)
$ sudo yum remove docker docker-common docker-selinux docker-engine
[[email protected] ~]# sudo yum remove docker docker-common docker-selinux docker-engine 已加载插件:fastestmirror, langpacks 参数 docker 没有匹配 参数 docker-common 没有匹配 参数 docker-selinux 没有匹配 参数 docker-engine 没有匹配 不删除任何软件包 [[email protected] ~]#
4、安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的
$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2
[[email protected] ~]# sudo yum install -y yum-utils device-mapper-persistent-data lvm2 已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: centos.ustc.edu.cn * extras: mirrors.zju.edu.cn * updates: centos.ustc.edu.cn 软件包 yum-utils-1.1.31-50.el7.noarch 已安装并且是最新版本 软件包 device-mapper-persistent-data-0.7.3-3.el7.x86_64 已安装并且是最新版本 软件包 7:lvm2-2.02.180-10.el7_6.7.x86_64 已安装并且是最新版本 无须任何处理
5、设置yum源
$ sudo yum-config-manager –add-repo https://download.docker.com/linux/centos/docker-ce.repo
[[email protected] ~]# cat /etc/yum.repos.d/docker-ce.repo [docker-ce-stable] name=Docker CE Stable - $basearch baseurl=https://download.docker.com/linux/centos/7/$basearch/stable enabled=1 gpgcheck=1 gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-stable-debuginfo] name=Docker CE Stable - Debuginfo $basearch baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/stable enabled=0 gpgcheck=1 gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-stable-source] name=Docker CE Stable - Sources baseurl=https://download.docker.com/linux/centos/7/source/stable enabled=0 gpgcheck=1 gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-edge] name=Docker CE Edge - $basearch baseurl=https://download.docker.com/linux/centos/7/$basearch/edge enabled=0 gpgcheck=1 gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-edge-debuginfo] name=Docker CE Edge - Debuginfo $basearch baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/edge enabled=0 gpgcheck=1 gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-edge-source] name=Docker CE Edge - Sources baseurl=https://download.docker.com/linux/centos/7/source/edge enabled=0 gpgcheck=1 gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-test] name=Docker CE Test - $basearch baseurl=https://download.docker.com/linux/centos/7/$basearch/test enabled=0 gpgcheck=1 gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-test-debuginfo] name=Docker CE Test - Debuginfo $basearch baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/test enabled=0 gpgcheck=1 gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-test-source] name=Docker CE Test - Sources baseurl=https://download.docker.com/linux/centos/7/source/test enabled=0 gpgcheck=1 gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-nightly] name=Docker CE Nightly - $basearch baseurl=https://download.docker.com/linux/centos/7/$basearch/nightly enabled=0 gpgcheck=1 gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-nightly-debuginfo] name=Docker CE Nightly - Debuginfo $basearch baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/nightly enabled=0 gpgcheck=1 gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-nightly-source] name=Docker CE Nightly - Sources baseurl=https://download.docker.com/linux/centos/7/source/nightly enabled=0 gpgcheck=1 gpgkey=https://download.docker.com/linux/centos/gpg
6、可以查看所有仓库中所有docker版本,并选择特定版本安装
$ yum list docker-ce –showduplicates | sort -r
[[email protected] ~]# yum list docker-ce --showduplicates | sort -r 已加载插件:fastestmirror, langpacks 可安装的软件包 * updates: centos.ustc.edu.cn Loading mirror speeds from cached hostfile * extras: mirrors.zju.edu.cn docker-ce.x86_64 3:18.09.7-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.6-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.5-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.4-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.3-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.2-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.1-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stable docker-ce.x86_64 18.06.3.ce-3.el7 docker-ce-stable docker-ce.x86_64 18.06.2.ce-3.el7 docker-ce-stable 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: centos.ustc.edu.cn
7、安装docker
$ sudo yum install docker-ce #由于repo中默认只开启stable仓库,故这里安装的是最新稳定版18.09.7
$ sudo yum install <FQPN> # 例如:sudo yum install docker-ce-17.12.0.ce
[[email protected] ~]# sudo yum install docker-ce 已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: centos.ustc.edu.cn * extras: mirrors.zju.edu.cn * updates: centos.ustc.edu.cn 正在解决依赖关系 --> 正在检查事务 ---> 软件包 docker-ce.x86_64.3.18.09.7-3.el7 将被 安装 --> 正在处理依赖关系 container-selinux >= 2.9,它被软件包 3:docker-ce-18.09.7-3.el7.x86_64 需要 --> 正在处理依赖关系 containerd.io >= 1.2.2-3,它被软件包 3:docker-ce-18.09.7-3.el7.x86_64 需要 --> 正在处理依赖关系 docker-ce-cli,它被软件包 3:docker-ce-18.09.7-3.el7.x86_64 需要 --> 正在检查事务 ---> 软件包 container-selinux.noarch.2.2.99-1.el7_6 将被 安装 ---> 软件包 containerd.io.x86_64.0.1.2.6-3.3.el7 将被 安装 ---> 软件包 docker-ce-cli.x86_64.1.18.09.7-3.el7 将被 安装 --> 解决依赖关系完成 依赖关系解决 ==================================================================================================================================== Package 架构 版本 源 大小 ==================================================================================================================================== 正在安装: docker-ce x86_64 3:18.09.7-3.el7 docker-ce-stable 19 M 为依赖而安装: container-selinux noarch 2:2.99-1.el7_6 extras 39 k containerd.io x86_64 1.2.6-3.3.el7 docker-ce-stable 26 M docker-ce-cli x86_64 1:18.09.7-3.el7 docker-ce-stable 14 M 事务概要 ==================================================================================================================================== 安装 1 软件包 (+3 依赖软件包) 总下载量:59 M 安装大小:243 M Is this ok [y/d/N]: y
8、启动并加入开机启动
$ sudo systemctl start docker
$ sudo systemctl enable docker
[[email protected] ~]# sudo systemctl start docker [[email protected] ~]# sudo 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-07-04 19:00:15 CST; 5s ago Docs: https://docs.docker.com Main PID: 39515 (dockerd) Tasks: 12 Memory: 31.6M CGroup: /system.slice/docker.service └─39515 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock 7月 04 19:00:14 localhost.localdomain dockerd[39515]: time="2019-07-04T19:00:14.543267103+08:00" level=info msg="pickfirstB...=grpc 7月 04 19:00:14 localhost.localdomain dockerd[39515]: time="2019-07-04T19:00:14.543329196+08:00" level=info msg="pickfirstB...=grpc 7月 04 19:00:14 localhost.localdomain dockerd[39515]: time="2019-07-04T19:00:14.575321922+08:00" level=info msg="Graph migr...onds" 7月 04 19:00:14 localhost.localdomain dockerd[39515]: time="2019-07-04T19:00:14.576607868+08:00" level=info msg="Loading co...art." 7月 04 19:00:14 localhost.localdomain dockerd[39515]: time="2019-07-04T19:00:14.873847435+08:00" level=info msg="Default br...ress" 7月 04 19:00:15 localhost.localdomain dockerd[39515]: time="2019-07-04T19:00:15.100425068+08:00" level=info msg="Loading co...one." 7月 04 19:00:15 localhost.localdomain dockerd[39515]: time="2019-07-04T19:00:15.140608095+08:00" level=info msg="Docker dae....09.7 7月 04 19:00:15 localhost.localdomain dockerd[39515]: time="2019-07-04T19:00:15.140901115+08:00" level=info msg="Daemon has...tion" 7月 04 19:00:15 localhost.localdomain dockerd[39515]: time="2019-07-04T19:00:15.151981654+08:00" level=info msg="API listen...sock" 7月 04 19:00:15 localhost.localdomain systemd[1]: Started Docker Application Container Engine. Hint: Some lines were ellipsized, use -l to show in full. [[email protected] ~]# sudo systemctl enable docker Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service. [[email protected] ~]#
9、验证安装是否成功(有client和service两部分表示docker安装启动都成功了)
$ docker version
[[email protected] ~]# docker version Client: Version: 18.09.7 API version: 1.39 Go version: go1.10.8 Git commit: 2d0083d Built: Thu Jun 27 17:56:06 2019 OS/Arch: linux/amd64 Experimental: false Server: Docker Engine - Community Engine: Version: 18.09.7 API version: 1.39 (minimum version 1.12) Go version: go1.10.8 Git commit: 2d0083d Built: Thu Jun 27 17:26:28 2019 OS/Arch: linux/amd64 Experimental: false