Updated 10/10/2018
With the new feature in the --config docker option, you no longer need to install Proxy in the Dockerfile. You can have the same Dockerfile for use in a 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 installing proxies with httpProxy, httpsProxy, ftpProxy and noProxy .
{ "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" } } }
If necessary ~/.docker/config.json and the proxy IP address and port and save in ~/.docker/config.json
After you configure it correctly, you can start the Docker build and run Docker as usual.
$ docker build -t demo . $ docker run -ti --rm demo env|grep -ri proxy (standard input):http_proxy=http:
Old answer
Below setting in Dockerfile works for me. I tested on CoreOS , Vagrant and boot2docker . Assume proxy port 3128
In Centos:
ENV http_proxy=ip:3128 ENV https_proxy=ip:3128
In Ubuntu:
ENV http_proxy 'http://ip:3128' ENV https_proxy 'http://ip:3128'
Be careful with the format, some have http in it, some don't, some have a single quota. if the IP address is 192.168.0.193, then the setting will be:
In Centos:
ENV http_proxy=192.168.0.193:3128 ENV https_proxy=192.168.0.193:3128
In Ubuntu:
ENV http_proxy 'http://192.168.0.193:3128' ENV https_proxy 'http://192.168.0.193:3128'
If you need to install proxies in Coreos, for example, to pull out an image
cat /etc/systemd/system/docker.service.d/http-proxy.conf [Service] Environment="HTTP_PROXY=http://192.168.0.193:3128"