基本上是参考菜鸟教程的 http://www.runoob.com/docker/centos-docker-install.html
但是遇到些问题以及解决方案。
1. 安装, 命令
yum install docker
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
yum -y install docker-ce
yum -y --skip-broken install docker-ce
systemctl start docker
systemctl status docker.service
遇到问题: 在最后一步中, 启动docker service的时候,遇到问题如下
failed at last:
]# systemctl status docker.service
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2019-05-22 17:52:36 CST; 19s ago
Docs: http://docs.docker.com
Process: 16597 ExecStart=/usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --defaul t-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-path=/usr/libexec/docker/docker-proxy-current -- init-path=/usr/libexec/docker/docker-init-current --seccomp-profile=/etc/docker/seccomp.json $OPTIONS $DOCKER_STORAGE_OPTIONS $DOCKER_NETWORK_OPTIONS $ADD_REGISTRY $BLOCK_REGISTRY $INSECURE_REGISTRY $REGISTRIES (code=exited, status=1/FAILURE)
Main PID: 16597 (code=exited, status=1/FAILURE)
May 22 17:52:35 host-10-76-24-68 systemd[1]: Starting Docker Application Container Engine...
May 22 17:52:35 host-10-76-24-68 dockerd-current[16597]: time="2019-05-22T17:52:35.251455113+08:00" level=warning msg="...und"
May 22 17:52:35 host-10-76-24-68 dockerd-current[16597]: time="2019-05-22T17:52:35.252939117+08:00" level=info msg="lib...606"
May 22 17:52:36 host-10-76-24-68 dockerd-current[16597]: time="2019-05-22T17:52:36.266268473+08:00" level=warning msg="over...
May 22 17:52:36 host-10-76-24-68 dockerd-current[16597]: Error starting daemon: SELinux is not supported with the overl...lse)
May 22 17:52:36 host-10-76-24-68 systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
May 22 17:52:36 host-10-76-24-68 systemd[1]: Failed to start Docker Application Container Engine.
May 22 17:52:36 host-10-76-24-68 systemd[1]: Unit docker.service entered failed state.
May 22 17:52:36 host-10-76-24-68 systemd[1]: docker.service failed.
解决方案,修改配置docker配置文件,“/etc/sysconfig/docker”, 将selinux 给disable。
modify /etc/sysconfig/docker,
line "OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false'" to "OPTIONS='--selinux-enabled=false --log-driver=journald --signature-verification=false'
"
then, run "systemctl start docker"
2. 启动 一个docker 容器,以“hello-world”作为实例
cmd: " docker run hello-world"
结果失败了,遇到问题如下(以下是问题的主要输出):
Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
解决方案 https://stackoverflow.com/questions/23111631/cannot-download-docker-images-behind-a-proxy
1. mkdir /etc/systemd/system/docker.service.d
2. 将以下两行输入到/etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:80/"
3. 重新加载数据
systemctl daemon-reload
4. 查看配置是否生效
systemctl show --property Environment docker
5. 重启docker 服务
systemctl restart docker
3. 重新尝试执行 “ docker run hello-world”, 发现新的问题
]# docker run hello-world
Unable to find image 'hello-world:latest' locally
Trying to pull repository docker.io/library/hello-world ...
latest: Pulling from docker.io/library/hello-world
1b930d010525: Pull complete
Digest: sha256:0e11c388b664df8a27a901dce21eb89f11d8292f7fca1b3e3c4321bf7897bffe
Status: Downloaded newer image for docker.io/hello-world:latest
/usr/bin/docker-current: Error response from daemon: error creating overlay mount to /var/lib/docker/overlay2/c5fffa6bac4381ba4f52fb9df9740a3e205c4abf2c2b5f35e2f91e2e1317b1e5/merged: invalid argument.
See '/usr/bin/docker-current run --help'.
systemctl stop docker #停止docker服务
rm -rf /var/lib/docker #清理镜像
vi /etc/sysconfig/docker-storage
修改 DOCKER_STORAGE_OPTIONS="--storage-driver overlay" #修改存储类型,把空的DOCKER_STORAGE_OPTIONS参数改为overlay:
systemctl start docker #启动docker应该就可以了