参考官方文档 https://docs.docker.com/install/linux/docker-ce/centos/
第一步, 卸载残留
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
第二步 ,设置仓库
先安装依赖包
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
添加稳定仓库
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
第三步 安装 docker
sudo yum install docker-ce docker-ce-cli containerd.io
安装过程中遇到错误
Error: Package: containerd.io-1.2.6-3.3.el7.x86_64 (docker-ce-stable)
Requires: container-selinux >= 2:2.74
Error: Package: 3:docker-ce-18.09.7-3.el7.x86_64 (docker-ce-stable)
Requires: container-selinux >= 2.9
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
从网上看有说使用阿里镜像直接装的,没能成功,主要是网不通
使用阿里云上的epel源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum install epel-release
yum install container-selinux
我使用直接下载的方式进行安装
wget http://mirror.centos.org/centos/7/extras/x86_64/Packages/container-selinux-2.74-1.el7.noarch.rpm
安装依赖
yum install policycoreutils-python
安装 selinux
rpm -ivh container-selinux-2.74-1.el7.noarch.rpm
接着使用第三步安装成功
第四步 启动 docker
sudo systemctl start docker
安装完成后, 需要关心一个问题, 那就是默认的docker image会存放到 /var/lib/docker 目录, 而这个目录往往空间不大, 长期使用的话会导致磁盘满, 所以需要修改这个目录到空间大的磁盘
docker info 命令可以看到当前使用的目录
首先将docker停下来
systemctl stop docker
然后 在空间大的磁盘创建目录
mkdir /data/docker
mkdir /etc/systemd/system/docker.service.d
vi /etc/systemd/system/docker.service.d/devicemapper.conf
写入内容
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd --graph=/data/docker
重启docker
systemctl daemon-reload
systemctl restart docker
systemctl enable docker
确定没问题后,删除原目录 rm -rf /var/lib/docker
我在设置这个目录的时候,遇到一台机器无法重启, 去掉这个配置就可以启来, 怀疑是文件 devicemapper.conf 内容写的不对,反复修改了一下, 后来又可以启动了. 猜测应该是文件里带不一些不可见的字符吧
下面列出错误信息供参考, 解决问题的核心就是要 systemctl daemon-reload , 要把文件写对, 记得首先要把docker stop掉
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
使用journalctl -xe也没看出来问题
报错信息如下
-- The result is failed.
Jul 02 14:31:06 ignite2 systemd[1]: docker.service failed.
Jul 02 14:31:06 ignite2 polkitd[828]: Unregistered Authentication Agent for unix-process:6220:8692866 (system bus name :1.388, object path /org/freedesk
ESC[
-- Subject: Unit docker.socket has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit docker.socket has begun starting up.
Jul 02 14:30:54 ignite2 systemd[1]: Listening on Docker Socket for the API.
-- Subject: Unit docker.socket has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit docker.socket has finished starting up.
--
-- The start-up result is done.
Jul 02 14:30:54 ignite2 systemd[1]: start request repeated too quickly for docker.service
Jul 02 14:30:54 ignite2 systemd[1]: Failed to start Docker Application Container Engine.
-- 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.
Jul 02 14:30:54 ignite2 systemd[1]: Unit docker.service entered failed state.
Jul 02 14:30:54 ignite2 systemd[1]: docker.service failed.
Jul 02 14:31:06 ignite2 sudo[6219]: root : TTY=pts/0 ; PWD=/etc/systemd/system/docker.service.d ; USER=root ; COMMAND=/bin/systemctl start docker
Jul 02 14:31:06 ignite2 sudo[6219]: pam_limits(sudo:session): unknown limit item 'noproc'
Jul 02 14:31:06 ignite2 sudo[6219]: pam_limits(sudo:session): unknown limit item 'noproc'
Jul 02 14:31:06 ignite2 polkitd[828]: Registered Authentication Agent for unix-process:6220:8692866 (system bus name :1.388 [/usr/bin/pkttyagent --notif
Jul 02 14:31:06 ignite2 systemd[1]: start request repeated too quickly for docker.service
Jul 02 14:31:06 ignite2 systemd[1]: Failed to start Docker Application Container Engine.
-- 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.
Jul 02 14:31:06 ignite2 systemd[1]: docker.service failed.
Jul 02 14:31:06 ignite2 polkitd[828]: Unregistered Authentication Agent for unix-process:6220:8692866 (system bus name :1.388, object path /org/freedesk
ESC[
-- Subject: Unit docker.socket has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit docker.socket has begun starting up.
Jul 02 14:30:54 ignite2 systemd[1]: Listening on Docker Socket for the API.
-- Subject: Unit docker.socket has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit docker.socket has finished starting up.
--
-- The start-up result is done.
Jul 02 14:30:54 ignite2 systemd[1]: start request repeated too quickly for docker.service
Jul 02 14:30:54 ignite2 systemd[1]: Failed to start Docker Application Container Engine.
-- 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.
Jul 02 14:30:54 ignite2 systemd[1]: Unit docker.service entered failed state.
Jul 02 14:30:54 ignite2 systemd[1]: docker.service failed.
Jul 02 14:31:06 ignite2 sudo[6219]: root : TTY=pts/0 ; PWD=/etc/systemd/system/docker.service.d ; USER=root ; COMMAND=/bin/systemctl start docker
Jul 02 14:31:06 ignite2 sudo[6219]: pam_limits(sudo:session): unknown limit item 'noproc'
Jul 02 14:31:06 ignite2 sudo[6219]: pam_limits(sudo:session): unknown limit item 'noproc'
Jul 02 14:31:06 ignite2 polkitd[828]: Registered Authentication Agent for unix-process:6220:8692866 (system bus name :1.388 [/usr/bin/pkttyagent --notif
Jul 02 14:31:06 ignite2 systemd[1]: start request repeated too quickly for docker.service
Jul 02 14:31:06 ignite2 systemd[1]: Failed to start Docker Application Container Engine.
-- 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.
Jul 02 14:31:06 ignite2 systemd[1]: docker.service failed.
Jul 02 14:31:06 ignite2 polkitd[828]: Unregistered Authentication Agent for unix-process:6220:8692866 (system bus name :1.388, object path /org/freedesk
ESC[
-- Subject: Unit docker.socket has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit docker.socket has begun starting up.
Jul 02 14:30:54 ignite2 systemd[1]: Listening on Docker Socket for the API.
-- Subject: Unit docker.socket has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit docker.socket has finished starting up.
--
-- The start-up result is done.
Jul 02 14:30:54 ignite2 systemd[1]: start request repeated too quickly for docker.service
Jul 02 14:30:54 ignite2 systemd[1]: Failed to start Docker Application Container Engine.
-- 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.
Jul 02 14:30:54 ignite2 systemd[1]: Unit docker.service entered failed state.
Jul 02 14:30:54 ignite2 systemd[1]: docker.service failed.
Jul 02 14:31:06 ignite2 sudo[6219]: root : TTY=pts/0 ; PWD=/etc/systemd/system/docker.service.d ; USER=root ; COMMAND=/bin/systemctl start docker
Jul 02 14:31:06 ignite2 sudo[6219]: pam_limits(sudo:session): unknown limit item 'noproc'
Jul 02 14:31:06 ignite2 sudo[6219]: pam_limits(sudo:session): unknown limit item 'noproc'
Jul 02 14:31:06 ignite2 polkitd[828]: Registered Authentication Agent for unix-process:6220:8692866 (system bus name :1.388 [/usr/bin/pkttyagent --notif
Jul 02 14:31:06 ignite2 systemd[1]: start request repeated too quickly for docker.service
Jul 02 14:31:06 ignite2 systemd[1]: Failed to start Docker Application Container Engine.
-- 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.
Jul 02 14:31:06 ignite2 systemd[1]: docker.service failed.
Jul 02 14:31:06 ignite2 polkitd[828]: Unregistered Authentication Agent for unix-process:6220:8692866 (system bus name :1.388, object path /org/freedes