CentOS 7.0,无外网直接访问权限,有一台代理服务器。php
首先安装docker-ce,参考http://blog.51cto.com/aaronsa/2056882html
除非特殊说明,如下操做都用root用户:linux
$ export http_proxy=http://xxxx $ export https_proxy=http://xxxx $ yum install -y yum-utils # 安装yum-config-manager $ yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo # 添加docker-ce yum源 $ yum install docker-ce $ systemctl start docker
第一个坑,启动失败,经过journalctl -xe查看启动日志,报错docker
devmapper: Error while creating filesystem xfs on device ....
json
参考http://www.cnblogs.com/FoChen/p/8708932.htmlubuntu
$ yum update xfsprogs
第二个坑,普通用户没法使用docker命令,报错swift
Got permission denied while trying to connect to the Docker daemon socket at ...centos
查了一下资料,原来docker命令经过一个Unix socket与docker daemon通讯,涉及到对Unix socket 访问权限问题,参考http://www.javashuo.com/article/p-nlbifuxw-bq.htmlapi
查了一下已经有docker组了,应该是yum install docker-ce时自动建立的,因而把普通用户添加进docker组就能够了;浏览器
$ gpasswd -a <user> docker
普通用户须要从新登陆;
第三个坑,docker pull hello-world,报错:
Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
确认了一下代理服务器,不是代理服务器出了问题;
在浏览器里试了一下https://registry-1.docker.io,没有内容,觉得是被墙了,大误,致使走了一大段错路,后来回头想一想看,这应该是个api服务器,只是对空请求返回空结果而已,HTTP返回码是200,不是被墙,哪怕当时试一下https://registry-1.docker.io/v2/,都不会走这条弯路;
刚开始按照错误思路,想添加国内registry镜像,查找资料:
既然是错误思路,固然没有解决个人问题,不过也不算是空手而归,对docker的架构有了些微了解:
正确思路是将代理设置到dockerd的环境变量里,这就涉及到了systemd的一点知识,参考了Arch-wiki;
而后重启dockerd服务;
$ vi /etc/systemd/system/docker.service.d/proxy.conf [Service] Environment="HTTP_PROXY=192.168.1.1:8080" Environment="HTTPS_PROXY=192.168.1.1:8080" $ systemctl daemon-reload $ systemctl show docker --property Environment #确认环境变量生效 $ systemctl restart docker
用普通用户再试一下:
$ docker pull hello-world Using default tag: latest latest: Pulling from library/hello-world 9bb5a5d4561a: Pull complete Digest: sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77 Status: Downloaded newer image for hello-world:latest $ docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest e38bc07ac18e 2 weeks ago 1.85kB $ docker run hello-world Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/engine/userguide/