Docker安装手册(CentOS7)

运行环境:

[root@localhost ~]# cat /etc/redhat-release

CentOS Linux release 7.5.1804 (Core)

 

Docker 运行在 CentOS 7 上,要求系统为64位、系统内核版本为 3.10 以上。通过uname -r 命令查看内核版本。

[root@localhost /]# uname -r

3.10.0-862.el7.x86_64

 

从 2017 年 3 月开始 docker 在原来的基础上分为两个分支版本: Docker CE 和 Docker EE。Docker CE 即社区免费版,社区版分为stable和edge两种发布方式,stable版本是季度发布方式,edge版本是月份发布方式。Docker EE 即企业版,强调安全,但需付费使用。本文介绍 Docker CE 的安装使用。

 

使用如下命令移除之前的版本:

yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine

 

[root@localhost ~]# yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine

已加载插件:fastestmirror

参数 docker 没有匹配

参数 docker-client 没有匹配

参数 docker-client-latest 没有匹配

参数 docker-common 没有匹配

参数 docker-latest 没有匹配

参数 docker-latest-logrotate 没有匹配

参数 docker-logrotate 没有匹配

参数 docker-selinux 没有匹配

参数 docker-engine-selinux 没有匹配

参数 docker-engine 没有匹配

不删除任何软件包

(如出现以上提示信息表示之前未安装docker)

 

1. 安装依赖的包。yum-utils, device-mapper-presistent-data, 和lvm2

[root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2

已加载插件:fastestmirror

Determining fastest mirrors

* base: mirrors.shu.edu.cn

* extras: ftp.sjtu.edu.cn

* updates: ftp.sjtu.edu.cn

base

(省略...)

已安装:

yum-utils.noarch 0:1.1.31-46.el7_5

作为依赖被安装:

libxml2-python.x86_64 0:2.9.1-6.el7_2.3 python-chardet.noarch 0:2.2.1-1.el7_1 python-kitchen.noarch 0:1.1.1-5.el7

完毕!

 

2. 添加Docker软件包源yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

(推荐使用国内源:http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo)

 

[root@localhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

已加载插件:fastestmirror

adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo

repo saved to /etc/yum.repos.d/docker-ce.repo

 

3. 开启edge版本库,关闭test版本库。这些版本库也包含在docker-ce.repo中,默认不可用,可以和稳定版本库一起开启:

[root@localhost ~]# yum-config-manager --enable docker-ce-edge

已加载插件:fastestmirror

(省略信息...)

[root@localhost ~]# yum-config-manager --disable docker-ce-test

已加载插件:fastestmirror

(省略信息...)

 

4.更新 yum 缓存(yum makecache fast)

[root@localhost ~]# yum makecache fast

已加载插件:fastestmirror

Loading mirror speeds from cached hostfile

(省略信息)

元数据缓存已建立

 

5.查看指定的版本(yum list docker-ce --showduplicates|sort -r)

[root@localhost ~]# yum list docker-ce --showduplicates|sort -r

已加载插件:fastestmirror

可安装的软件包

* updates: ftp.sjtu.edu.cn

Loading mirror speeds from cached hostfile

* extras: ftp.sjtu.edu.cn

docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable

docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-edge

(省略信息...)

* base: mirrors.shu.edu.cn

 

6.安装指定版本(yum install docker-ce-18.06.1.ce -y)

[root@localhost ~]# yum install docker-ce-18.06.1.ce -y

(省略信息...)

已安装:

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

作为依赖被安装:

audit-libs-python.x86_64 0:2.8.1-3.el7_5.1 checkpolicy.x86_64 0:2.5-6.el7 container-selinux.noarch 2:2.68-1.el7 libcgroup.x86_64 0:0.41-15.el7

libsemanage-python.x86_64 0:2.5-11.el7 policycoreutils-python.x86_64 0:2.5-22.el7 python-IPy.noarch 0:0.75-6.el7 setools-libs.x86_64 0:3.3.8-2.el7

作为依赖被升级:

audit.x86_64 0:2.8.1-3.el7_5.1 audit-libs.x86_64 0:2.8.1-3.el7_5.1

完毕!

 

7.启动 Docker 服务(systemctl start docker)

[root@localhost ~]# systemctl start docker

 

测试:

查看版本(docker version)

[root@localhost ~]# 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

 

执行helloword(docker run hello-world)

[root@localhost ~]# docker run hello-world

Unable to find image 'hello-world:latest' locally

latest: Pulling from library/hello-world

d1725b59e92d: Pull complete

Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788

Status: Downloaded newer image for hello-world:latest

(省略信息...)

 

 

8.删除Docker

yum remove docker-ce

rm -rf /var/lib/docker

 

-------------------------------------------------------------------------------------------------------------------------------------------------------

FAQ:

 

1. 启动报错:

[root@localhost docker]# systemctl start docker

Job for docker.service failed because start of the service was attempted too often. See "systemctl status docker.service" and "journalctl -xe" for details.

To force a start use "systemctl reset-failed docker.service" followed by "systemctl start docker.service" again.

 

原因:在/etc/docker路径下增加了错误的daemon.json 文件导致

解决:删除此文件或修正文件中的json格式的信息

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值