How to configure docker container proxy?
You can set the proxy environment variables when starting the container, for example:
docker container run \ -e HTTP_PROXY=http://username:password@proxy2.domain.com \ -e HTTPS_PROXY=http://username:password@proxy2.domain.com \ myimage
If you want the proxy-server to be automatically used when starting a container, you can configure default proxy-servers in the Docker CLI configuration file (~/.docker/config.json
). You can find instructions for this in the networking section in the user guide.
For example:
{ "proxies": { "default": { "httpProxy": "http://username:password@proxy2.domain.com", "httpsProxy": "http://username:password@proxy2.domain.com" } }}
To verify if the ~/.docker/config.json
configuration is working, start a container and print its env
:
docker container run --rm busybox envPATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binHOSTNAME=220e4df13604HTTP_PROXY=http://username:password@proxy2.domain.comhttp_proxy=http://username:password@proxy2.domain.comHTTPS_PROXY=http://username:password@proxy2.domain.comhttps_proxy=http://username:password@proxy2.domain.comHOME=/root
you need instruct the apt script to connect through proxy inside the container
# echo 'Acquire::http::proxy "proxy:port/";' > /etc/apt/apt.conf.d/40proxy
remember, this should be written inside the container
and in the machine that have docker running, the proxy should be configured like people said before in their comments