LoginSignup
17
18

More than 5 years have passed since last update.

Proxy環境下でDocker Toolboxを使う

Posted at

チュートリアルを見ながらDocker Toolboxで遊ぼうとしたらProxy設定ではまりました。
Docker Quickstart Terminalで docker run hello-world してもエラー。
docker-machineにProxy設定が入っていないのが原因でした。

環境

  • Windows7
  • Docker Toolbox 1.11.1
  • Proxy通さないと外にいけないネットワーク

Proxyが有効になったdocker-machineを作成しなおす

Docker Quickstart Terminalを起動すると、最初に default という docker-machine が作られます。これにProxy設定が入っていないので、dokcer run hello-worldで hello-world の dockerイメージを取りに行けていませんでした。

Docker Quickstart Terminalが起動するstart.sh を読んだところ、環境変数 HTTP_PROXY, HTTPS_PROXY, NO_PROXYを設定してあればそれらを使って docker-machine を作ってくれそうなのでやってみます。

まず、すでに作成されたdefaultのdocker-machineを削除。

$ docker-machine rm -f default

Windowsで以下になるように環境変数を設定する。

HTTP_PROXY=http://your-proxy:port/
HTTPS_PROXY=http://your-proxy:port/
NO_PROXY=127.0.0.1

で、Docker- Quickstart Terminalをいざ実行。

…なんか、boot2docker自体をupdateしてくれました。

Running pre-create checks...
(default) Default Boot2Docker ISO is out-of-date, downloading the latest release
...
(default) Latest release for github.com/boot2docker/boot2docker is v1.12.1
(default) Downloading C:\Users\user\.docker\machine\cache\boot2docker.iso from
 https://github.com/boot2docker/boot2docker/releases/download/v1.12.1/boot2docke
r.iso...
(default) 0%....10%....20%....30%....40%....50%....60%....70%....80%....90%....1
00%
Creating machine...
(略)

起動したら確認。

$ docker-machine ls
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DO
CKER    ERRORS
default   *        virtualbox   Running   tcp://192.168.99.100:2376           v1.12.1

いざ docker run

$ docker run hello-world
C:\Program Files\Docker Toolbox\docker.exe: An error occurred trying to connect:
 Post https://192.168.99.100:2376/v1.23/containers/create: CONNECTnotallowed.
See 'C:\Program Files\Docker Toolbox\docker.exe run --help'.

あら?

docker-mchineの192.168.99.100にもproxy経由でいこうとしていたんでした。docker-machineのIPをNO_PROXYに追加します。

$ export NO_PROXY=$NO_PROXY,192.168.99.100

$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c04b14da8d14: Pull complete
Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9
Status: Downloaded newer image for hello-world:latest

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.
 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 Hub account:
 https://hub.docker.com

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

無事にhello-worldできました。
sshでdocker-machineに入って確認したら、ちゃんとproxy設定できています。

docker@default:~$ cat /var/lib/boot2docker/profile

EXTRA_ARGS='
--label provider=virtualbox

'
CACERT=/var/lib/boot2docker/ca.pem
DOCKER_HOST='-H tcp://0.0.0.0:2376'
DOCKER_STORAGE=aufs
DOCKER_TLS=auto
SERVERKEY=/var/lib/boot2docker/server-key.pem
SERVERCERT=/var/lib/boot2docker/server.pem

export "HTTP_PROXY=http://www-proxy.sra.co.jp:80/"
export "HTTPS_PROXY=http://www-proxy.sra.co.jp:80/"
export "NO_PROXY=127.0.0.1"

docker-toolbox Troubleshooting

ドキュメントにちゃんと書いてありますね。
https://docs.docker.com/toolbox/faqs/troubleshoot/#/http-proxies-and-connectivity-errors

17
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
18