LoginSignup
30
37

More than 5 years have passed since last update.

proxy環境下でwindowsにdockerを導入する

Last updated at Posted at 2016-02-09

以下の環境で、dockerを導入します。
* Windows7 SP1
* DockerToolbox-1.10.0

docker toolboxを使って色々インストール

windowsにdockerをinstallする場合、docker toolboxを利用することが推奨されています。
docker toolboxはここからDLできます。
ただし、proxy環境下ではinstallerを実行してもプロセスが応答なしになったままうんともすんとも言わないのでどうしようもありません。
~完~

原因

導入開始と同時に詰んだので、しばし呆然としていたところ、5分後ぐらいにひょっこりウィンドウが現れました。

install途中もプロセスが応答なしにちょいちょいなりますが、慌てずゆっくり待つと、そのうちinstallが終わります。

ちなみに、docker/toolboxissueを見てみたところ、同様の現象に遭遇してる人たちが居ました。
やっぱりproxy経由だと起きるっぽいです。

docker machineの作成

オフィシャルの説明ではこの後、Desktopに生成されたDocker Quickstart Terminalというショートカットを実行するのですが、実行するとLooks like something went wrong...という不穏なメッセージが表示されるので、やめておきます。
やってることはdocker-machineを作ってるだけっぽいので、自分でやりましょう。
proxy周りでこけているような気がしなくもないので、その辺もよしなにします。
こちらの情報を参考にdocker-machineを作ります。
(http_proxyとhttps_proxyという環境変数が設定されている前提です。)

$ docker-machine create -d virtualbox --engine-env http_proxy=${http_proxy} --engine-env https_proxy=${https_proxy} default

次にdocker-machine用の環境変数を、ここを参考にしながら設定します。

$ docker-machine env default --shell cmd
SET DOCKER_TLS_VERIFY=1
SET DOCKER_HOST=tcp://192.168.99.100:2376
SET DOCKER_CERT_PATH=C:\Users\user\.docker\machine\machines\default
SET DOCKER_MACHINE_NAME=default
REM Run this command to configure your shell:
REM     FOR /f "tokens=*" %i IN ('docker-machine env default --shell cmd') DO %i

言われたとおりにします。

$ FOR /f "tokens=*" %i IN ('docker-machine env default --shell
md') DO %i
SET DOCKER_TLS_VERIFY=1
SET DOCKER_HOST=tcp://192.168.99.100:2376
SET DOCKER_CERT_PATH=C:\Users\user\.docker\machine\machines\default
SET DOCKER_MACHINE_NAME=default

これでよさそうですが、このままだと仮想マシンに接続するときもproxy経由になってしまうので、以下のように怒られます。

$ docker ps
An error occurred trying to connect: Get https://192.168.99.100:2376/v1.22/conta
iners/json: Forbidden

proxyを通らないように環境変数で設定しましょう。
(IPアドレスは上のコマンドで表示されたものに変更してください)

$ SET NO_PROXY=192.168.99.100;

docker側のproxy設定

docker pull時にproxyを知らないとimageが取って来れないので設定します。

$ docker-machine ssh
# sudo vi /var/lib/boot2docker/profile

以下を追記します。

export HTTP_PROXY=http://xxx.xxx.xxx.xxx:8880
export HTTPS_PROXY=$HTTP_PROXY
export NO_PROXY=localhost,127.0.0.1,.sock

いざ実行

では満を持してdockerを実行してみましょう。

$ 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.
 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/userguide/

めでたい!

30
37
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
30
37