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/