docker-machine behind corporate proxy
Asked Answered
A

6

32

I am trying to use docker-machine to create an instance on a private cloud (Openstack) that is behind a corporate http proxy.

Is it possible to tell docker-machine to use the proxy or do I need to have a glance image that is already pre-configure with the http_proxy env variable?

Ailssa answered 2/7, 2015 at 15:47 Comment(2)
this should fix your issue. github.com/docker/machine/blob/…Tocantins
Indeed it does. I think it was added with v0.4.0 and was not available with v0.3.0, thanks. Wanna post it as an answer so I accept it?Ailssa
R
38

As previously mentioned, you can edit the file at

$HOME\.docker\machine\machines\default\config.json

and set the HTTP_PROXY, HTTPS_PROXY and NO_PROXY variables (or delete them):

 "HostOptions": {
        "Driver": "",
        ...
        "EngineOptions": {
           ...
            "Env": [
              "HTTP_PROXY=http://10.121.8.110:8080",
              "HTTPS_PROXY=http://10.121.8.110:8080",
              "NO_PROXY=192.168.23.4"
            ],

After the file has edited, you only have to execute:

docker-machine provision 
Rooky answered 27/9, 2016 at 21:52 Comment(2)
This applies to the engine and is needed for example to pull images.Sludge
what if there is currently no default provisioned and there is no "machines" folder inside $HOME\.docker\machine\ ?Gunilla
T
28

With current docker machine version, I can't find better way to do the change as in boot2docker (Docker/Boot2Docker: Set HTTP/HTTPS proxies for docker on OS X)

If you manually set the proxy in /var/lib/boot2docker/profile in docker machine, after restart it, the proxy setting will be removed automatically.

So I have to create a docker machine with --engine-env set for proxy

docker-machine create -d virtualbox \
    --engine-env HTTP_PROXY=http://example.com:8080 \
    --engine-env HTTPS_PROXY=https://example.com:8080 \
    --engine-env NO_PROXY=example2.com \
    proxybox

NOTES:

This is a two-years-old answer, there are a lot of changes happened in docker, so if you still can't make it work behind the proxy, please read @Senri's answer and others.

Documentation: create docker machine

Tocantins answered 19/8, 2015 at 2:43 Comment(3)
If you're using something like CNTLM to create a proxy on your host machine's localhost, you'll need to set the VM's proxy to http://10.0.2.2:<host's proxy port> (see this question).Pluperfect
Just editing /var/lib/boot2docker/profile didn't work for me. @Senri's solution worked though.Ecdysiast
Reasonable, the updates in docker happens every day, we can't catch all changes in time, I will remove the update part.Tocantins
K
5

Existing docker-machine config can be modified to add environment for the proxy. The config.json at $HOME/.docker/machine/machines//.config.json can be edited.

Add "HTTP_PROXY=http://example.com:8080" to Env in config.json. Restart the machine, and you are all set.

Keelin answered 21/8, 2015 at 7:10 Comment(0)
S
3

If you have already the machine (VM) created, you can configure the proxy like this :

1- SSH into the docker dev host: docker-machine ssh dev
2- Add the following lines to /var/lib/boot2docker/profile (this file is read-only, use sudo)
    export HTTP_PROXY=http://<proxy>:<port>
    export HTTPS_PROXY=http://<proxy>:<port>
3- Exit the ssh session and restart the docker machine: docker-machine restart dev 

Source

Stranger answered 14/12, 2017 at 14:39 Comment(1)
This worked for me!!!... I tried the above and it did not work for me... I dont know whyFrondescence
V
3

As of Docker 18.09, we can specify environment vars such as proxy to the container on the command line like so:

docker run --env HTTP_PROXY="172.10.13.14" -it myImage:latest /bin/bash

Additionally, we can specify these settings to the docker client by writing them in ~/.docker/config.json file like so:

{
 "proxies":
 {
   "default":
   {
     "httpProxy": "http://127.0.0.1:3001",
     "noProxy": "*.test.example.com,.example2.com"
   }
 }
}

More information is available on the docs.

Vaasa answered 21/12, 2018 at 11:26 Comment(1)
This seems to only affect newly started containers, but has no effect on the engine itself.Sludge
B
0

If the Docker-machine behind the corporate proxy:

Linux (Ubuntu, Debian):

sudo mkdir -p /etc/systemd/system/docker.service.d
cd /etc/systemd/system/docker.service.d/
sudo touch http-proxy.conf
sudo nano http-proxy.conf

# copy and paste in the file:
[Service] 
Environment="HTTP_PROXY=http://<PROXYIP>:3128"
Environment="HTTPS_PROXY=http://<PROXYIP>:3128"
Environment="NO_PROXY=localhost,192.168.1.0/16,10.*.*.*" 

sudo systemctl daemon-reload
sudo systemctl restart docker
sudo systemctl show --property=Environment docker

Windows:

Update environment variable using Powershell (with admin rights):

[Environment]::SetEnvironmentVariable("HTTP_PROXY", "http://<PROXYIP>:3128", [EnvironmentVariableTarget]::Machine)
[Environment]::SetEnvironmentVariable("HTTPS_PROXY", "http://<PROXYIP>:3128", [EnvironmentVariableTarget]::Machine)
[Environment]::SetEnvironmentVariable("NO_PROXY", "192.168.*.*, 172.24.*.*, 172.25.*.*, 10.*.*.*, localhost, 127.0.0.1, 0.0.0.0/8", [EnvironmentVariableTarget]::Machine)
Restart-Service docker
Bove answered 19/7, 2023 at 12:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.