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?
If you're running Docker for Desktop this is a really simple operation. You can do this from Docker's settings Docker > Preferences > Resources > Proxies . All you need to do is provide values for the following variables: HTTP_PROXY : the proxy server endpoint to handle HTTP calls.
We simply need to set the http_proxy and https_proxy environmental variables during build time. We can do this with the docker build command itself. $ sudo docker build -t curl --build-arg http_proxy=http://192.168.33.10:3128 . Or we can specify the http_proxy value using the ENV instruction within the Dockerfile .
docker-proxify is a docker-within-docker container that eases development when operating behind a restrictive firewall that requires a proxy server for outbound internet connectivity, by making the use of the proxy server transparent to the applications running inside the container.
docker run --network="host" Alternatively you can run a docker container with network settings set to host . Such a container will share the network stack with the docker host and from the container point of view, localhost (or 127.0. 0.1 ) will refer to the docker host.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With