With new feature in docker option --config
, you needn't set Proxy in Dockerfile any more. You can have same Dockerfile to be used in and out corporate environment.
--config string Location of client config files (default "~/.docker")
or environment variable DOCKER_CONFIG
`DOCKER_CONFIG` The location of your client configuration files.
$ export DOCKER_CONFIG=~/.docker
https://docs.docker.com/engine/reference/commandline/cli/
https://docs.docker.com/network/proxy/
I recommend to set proxy with httpProxy, httpsProxy, ftpProxy
and noProxy
(The official document misses the variable ftpProxy
which is useful sometimes)
{
"proxies":
{
"default":
{
"httpProxy": "http://127.0.0.1:3001",
"httpsProxy": "http://127.0.0.1:3001",
"ftpProxy": "http://127.0.0.1:3001",
"noProxy": "*.test.example.com,.example2.com"
}
}
}
Adjust proxy IP and port if needed and save to ~/.docker/config.json
After yo set properly with it, you can run docker build and docker run as normal.
$ docker build -t demo .
$ docker run -ti --rm demo env|grep -ri proxy
(standard input):http_proxy=http://127.0.0.1:3001
(standard input):HTTPS_PROXY=http://127.0.0.1:3001
(standard input):https_proxy=http://127.0.0.1:3001
(standard input):NO_PROXY=*.test.example.com,.example2.com
(standard input):no_proxy=*.test.example.com,.example2.com
(standard input):FTP_PROXY=http://127.0.0.1:3001
(standard input):ftp_proxy=http://127.0.0.1:3001
(standard input):HTTP_PROXY=http://127.0.0.1:3001
Below setting in Dockerfile works for me. I tested in CoreOS
, Vagrant
and boot2docker
. Suppose the proxy port is 3128
ENV http_proxy=ip:3128
ENV https_proxy=ip:3128
ENV http_proxy 'http://ip:3128'
ENV https_proxy 'http://ip:3128'
Be careful of the format, some have http in it, some haven't, some with single quota. if the IP address is 192.168.0.193, then the setting will be:
ENV http_proxy=192.168.0.193:3128
ENV https_proxy=192.168.0.193:3128
ENV http_proxy 'http://192.168.0.193:3128'
ENV https_proxy 'http://192.168.0.193:3128'
cat /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://192.168.0.193:3128"