Docker container, how to use host proxy

11,468

Solution 1

I fixed it by setting the proxy in /etc/default/docker.

I also had to unset the proxy in the environment variables:

unset http_proxy
unset https_proxy

Solution 2

If you don't want to use --network=host to isolate your Docker from the host's network, you need to make the host network available inside Docker.

When running docker use: (Linux, Docker version > 20.10)

--add-host=host.docker.internal:host-gateway

Say your proxy is running on port 3128, inside your docker container you need to set

http_proxy=http://host.docker.internal:3128

Also make sure that you set Gateway yes in /etc/cntlm.conf if that's the proxy you're using.

Share:
11,468
HMR
Author by

HMR

Like programming because interest me. Love getting paid for my hobby. I am available for mentoring, just send a message to harmmeiier at the gmail com.

Updated on June 09, 2022

Comments

  • HMR
    HMR almost 2 years

    Because I'm in China it is nearly impossible to use Docker Hub, Git, GitHub, npm and loads of other tools without a VPN.

    I finally found how to have the Docker daemon use a proxy (share VPN in the VPN client software on the host is the proxy server).

    But as soon as I run the container I'm behind the firewall again and the container is not using the host proxy. This would make it impossible to get anything from GitHub, use npm, Bower and lots of other things.

    How can I force the container to use the host proxy?