I am running docker on Debian Jessie which is behind a corporate proxy. To be able to download docker images, I need to add the following to my /etc/defaults/docker


I can confirm that this works.

However, in order to be able to access the interwebz from within my container, I need to start all sessions with --net host and then setup these env variables:

export http_proxy=http://localhost:3128/
export https_proxy=https://localhost:3128/
export ftp_proxy=${http_proxy}

Ideally, I would like for the container to not need the host network, and not to know about the proxy (i.e. all outbound calls to port 20, 80, 443 in the container go via the host's proxy port). Is that possible?

Failing that, is it possible to have a site setup, which will ensure that these env variables are set locally but never exported as part of an image?

UPDATE: I know I can pass these things with --env http_proxy=... etc, but that's clunky. I want it to work for all users on the system without having to use aliases.

2 Answers 2


See this SO answer:

Host server runs a container running a proxy (squid, in this case) that can do transparent proxying. That container has some iptables rules that NAT traffic into the proxy server - this means that container needs to run in privileged mode.

Host server also contains (and here's the magic) ip route table entries that re-route all traffic from any container but the proxy that was destined for port 80, through the proxy container.

That last bit essentially means that for port 80 traffic, the route from container to the rest of the world goes through the proxy container - giving it the chance to NAT and transparent proxy.


  • This will not work for "https".
    – ceving
    Dec 11, 2019 at 14:15

The Configure the Docker client official documentation shows how to easily solve this problem.

Edit the ~/.docker/config.json (or %USERPROFILE%\.docker\config.json) file and add the following JSON snippet:

    "proxies": {
        "default": {
            "httpProxy": "http://localhost:3128",
            "httpsProxy": "https://localhost:3128"

This solved my issue where running apt udpate inside a debian docker container would fail. After adding the proxy settings in that json file and starting a new docker container apt update started to work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.