[296]centos7安装docker

xiaoxiao2021-02-28  41

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

2、使用 root 权限登录 Centos。确保 yum 包更新到最新。(慎重,可能导致其它软件包不可用)

不要随便yum update 后果有时会导致系统启动不了,因为它会更新你的内核,如果更新失败,最好yum clean all

$ sudo yum update

3、卸载旧版本(如果安装过旧版本的话)

$ sudo yum remove docker docker-common docker-selinux docker-engine

4、安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的

$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2

5、设置yum源

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

6、可以查看所有仓库中所有docker版本,并选择特定版本安装

$ yum list docker-ce --showduplicates | sort -r

7、安装docker

$ sudo yum install docker-ce #由于repo中默认只开启stable仓库,故这里安装的是最新稳定版17.12.0 $ sudo yum install <FQPN> # 例如:sudo yum install docker-ce-17.12.0.ce

7.1更改docker的镜像源

安装好之后,更改docker的镜像源,修改或新增 /etc/docker/daemon.json

vi /etc/docker/daemon.json 修改成如下:

{ "registry-mirrors": ["http://hub-mirror.c.163.com"] } 或 { "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"] }

8、启动并加入开机启动

$ sudo systemctl start docker $ sudo systemctl enable docker

服务启、停、查、重启

service docker start/stop/status/restart chkconfig docker on

9、验证安装是否成功(有client和service两部分表示docker安装启动都成功了)

$ docker version

测试运行 hello-world

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

由于本地没有hello-world这个镜像,所以会下载一个hello-world的镜像,并在容器内运行。

10、其它 列出所有本地镜像

docker images

删除本地镜像

docker rmi centos

如果已经有基于此镜像的容器,需要先删除相应的容器再删除镜像。或者通过-f参数强制删除镜像,如docer rmi -f centos。

二、问题

1、因为之前已经安装过旧版本的docker,在安装的时候报错如下:

Transaction check error: file /usr/bin/docker from install of docker-ce-17.12.0.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64 file /usr/bin/docker-containerd from install of docker-ce-17.12.0.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64 file /usr/bin/docker-containerd-shim from install of docker-ce-17.12.0.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64 file /usr/bin/dockerd from install of docker-ce-17.12.0.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64

2、卸载旧版本的包

$ sudo yum erase docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64

卸载Docker CE

[root@centos_7 ~]# sudo yum remove docker-ce [root@centos_7 ~]# sudo rm -rf /var/lib/docker

3、再次安装docker

$ sudo yum install docker-ce

无法正常启动问题

[root@test ~]# service docker start Redirecting to /bin/systemctl start docker.service Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details. [root@localhost plugins]# journalctl -xe 5月 17 15:11:13 localhost.localdomain dockerd[10864]: time="2018-05-17T15:11:13+08:00" l 5月 17 15:11:13 localhost.localdomain dockerd[10864]: time="2018-05-17T15:11:13+08:00" l 5月 17 15:11:13 localhost.localdomain dockerd[10864]: time="2018-05-17T15:11:13+08:00" l 5月 17 15:11:13 localhost.localdomain dockerd[10864]: time="2018-05-17T15:11:13+08:00" l 5月 17 15:11:13 localhost.localdomain dockerd[10864]: time="2018-05-17T15:11:13+08:00" l 5月 17 15:11:13 localhost.localdomain dockerd[10864]: time="2018-05-17T15:11:13+08:00" l 5月 17 15:11:13 localhost.localdomain dockerd[10864]: time="2018-05-17T15:11:13+08:00" l 5月 17 15:11:13 localhost.localdomain dockerd[10864]: time="2018-05-17T15:11:13+08:00" l 5月 17 15:11:13 localhost.localdomain dockerd[10864]: time="2018-05-17T15:11:13+08:00" l 5月 17 15:11:13 localhost.localdomain dockerd[10864]: time="2018-05-17T15:11:13+08:00" l 5月 17 15:11:13 localhost.localdomain dockerd[10864]: time="2018-05-17T15:11:13+08:00" l 5月 17 15:11:13 localhost.localdomain dockerd[10864]: time="2018-05-17T15:11:13+08:00" l 5月 17 15:11:13 localhost.localdomain dockerd[10864]: Error starting daemon: error initi 5月 17 15:11:13 localhost.localdomain systemd[1]: docker.service: main process exited, c 5月 17 15:11:13 localhost.localdomain systemd[1]: Failed to start Docker Application Con -- Subject: Unit docker.service has failed -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel -- -- Unit docker.service has failed. -- -- The result is failed. 5月 17 15:11:13 localhost.localdomain systemd[1]: Unit docker.service entered failed sta 5月 17 15:11:13 localhost.localdomain systemd[1]: docker.service failed. 5月 17 15:11:13 localhost.localdomain systemd[1]: docker.service holdoff time over, sche 5月 17 15:11:13 localhost.localdomain systemd[1]: start request repeated too quickly for 5月 17 15:11:13 localhost.localdomain systemd[1]: Failed to start Docker Application Con -- Subject: Unit docker.service has failed -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel -- -- Unit docker.service has failed. -- -- The result is failed. 5月 17 15:11:13 localhost.localdomain systemd[1]: Unit docker.service entered failed sta 5月 17 15:11:13 localhost.localdomain systemd[1]: docker.service failed. [root@localhost packages]# systemctl status docker.service -l ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled) Active: failed (Result: start-limit) since 四 2018-05-17 14:55:09 CST; 7min ago Docs: https://docs.docker.com Process: 9940 ExecStart=/usr/bin/dockerd (code=exited, status=1/FAILURE) Main PID: 9940 (code=exited, status=1/FAILURE) 5月 17 14:55:09 localhost.localdomain systemd[1]: Failed to start Docker Application Container Engine. 5月 17 14:55:09 localhost.localdomain systemd[1]: Unit docker.service entered failed state. 5月 17 14:55:09 localhost.localdomain systemd[1]: docker.service failed. 5月 17 14:55:09 localhost.localdomain systemd[1]: docker.service holdoff time over, scheduling restart. 5月 17 14:55:09 localhost.localdomain systemd[1]: start request repeated too quickly for docker.service 5月 17 14:55:09 localhost.localdomain systemd[1]: Failed to start Docker Application Container Engine. 5月 17 14:55:09 localhost.localdomain systemd[1]: Unit docker.service entered failed state. 5月 17 14:55:09 localhost.localdomain systemd[1]: docker.service failed.

查看文件系统 /etc/docker/daemon.json 有没有这个文件,没有测创建它包括二级目录 docker 在daemon.json文件中输入以下内容:

[root@localhost plugins]# vi /etc/docker/daemon.json { "graph": "/mnt/docker-data", "storage-driver": "devicemapper", "registry-mirrors": ["http://hub-mirror.c.163.com"] }

我的问题是添加"storage-driver": "devicemapper"解决


使用脚本安装 Docker 1、使用 sudo 或 root 权限登录 Centos。 2、确保 yum 包更新到最新。(慎重,可能导致其它软件包不可用)

$ sudo yum update

3、执行 Docker 安装脚本。

$ curl -fsSL https://get.docker.com/ | sh

执行这个脚本会添加 docker.repo 源并安装 Docker。

4、启动 Docker 进程。

$ sudo service docker start

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

$ sudo docker run hello-world docker ps

到此,docker 在 CentOS 系统的安装完成。

镜像加速

鉴于国内网络问题,后续拉取 Docker 镜像十分缓慢,我们可以需要配置加速器来解决,我使用的是网易的镜像地址:http://hub-mirror.c.163.com。 新版的 Docker 使用 /etc/docker/daemon.json(Linux) 或者 %programdata%\docker\config\daemon.json(Windows) 来配置 Daemon。 请在该配置文件中加入(没有该文件的话,请先建一个):

# 如果没有此文件,则新建一个 vi /etc/docker/daemon.json { "registry-mirrors": ["http://hub-mirror.c.163.com"] }

参考:http://www.runoob.com/docker/centos-docker-install.html https://www.cnblogs.com/yufeng218/p/8370670.html http://blog.cheyo.net/280.html

问题参考:https://www.cnblogs.com/amoyzhu/p/5261393.html https://blog.csdn.net/qq_35904833/article/details/74189383 https://www.oschina.net/question/988854_2143631

转载请注明原文地址: https://www.6miu.com/read-2619862.html

最新回复(0)