開発環境
- Ubuntu 16.04
- Docker 17.09.0-ce
- プロキシサーバ利用
エラー内容
console
$ sudo su -
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/: dial tcp xxx.xxx.154.207:443: getsockopt: connection refused.
See 'docker run --help'.
原因
Dockerにプロキシサーバを設定していない場合、上記の接続エラーになる
対応手順
Dockerにプロキシサーバーを設定
console
# docker.service.dを作成してproxy設定を記述
$ mkdir /etc/systemd/system/docker.service.d
$ vi /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:80/"
Environment="NO_PROXY=localhost,127.0.0.0/8"
# reloadして設定内容を確認したらrestart
$ systemctl daemon-reload
$ systemctl show --property Environment docker
Environment=HTTP_PROXY=http://proxy.example.com:80/ NO_PROXY=localhost,127.0.0.0/8
$ sudo systemctl restart docker
設定したらもう一度docker runして確認
console
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
5b0f327be733: Pull complete
Digest: sha256:07d5f7800dfe37b8c2196c7b1c524c33808ce2e0f74e7aa00e603295ca9a0972
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
補足
- プロキシ設定済みでも別の原因で上記エラーが出る場合があります
- 参考:https://stackoverflow.com/questions/23111631/cannot-download-docker-images-behind-a-proxy