Reputation: 490
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?
Upvotes: 32
Views: 26726
Reputation: 2659
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
Upvotes: 0
Reputation: 45243
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
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
Upvotes: 28
Reputation: 776
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.
Upvotes: 3
Reputation: 919
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
Upvotes: 3
Reputation: 456
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
Upvotes: 38
Reputation: 1116
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.
Upvotes: 5