I'm trying to run docker image on MacOS with VPN turned on (TUN device). Docker container can access internet, but is not able to access resources behind vpn. What is the right way to make Docker go to VPN network?
I've tried docker run --net host
to make docker share host network, it didn't help. Host can access VPN resources, docker container can't resolve their names..
Encapsulating software within a container brings a lot of benefits, such as quicker deployment, easier development and - last but not least - isolation of your host system from the application.
AFAIK, in the case of Docker for Linux (standard distribution), the IP address of the host will always be 172.17. 0.1 (on the main network of docker, see comments to learn more). This is true of containers attached to the docker0 default bridge interface.
If you specify the --net=host option to the docker create or docker run commands, Docker uses the host's network stack for the container. The network configuration of the container is the same as that of the host and the container shares the service ports that are available to the host.
As long as the server running locally on your Mac or in another docker container is listening to 0.0. 0.0 , the docker container will be able to reach out at that address.
I had to restart docker after connecting host machine to VPN.
sudo systemctl restart docker docker start {name-of-container}
Not sure if it's best solution.
I took DNS that appears on my host after connecting to VPN
scutil --dns | grep 'nameserver\[[0-9]*\]' nameserver[0] : xxx.xxx.xxx.xxx
Modified docker run command:
docker run --cidfile="docker.pid" --dns=xxx.xxx.xxx.xxx --publish-all
Now docker container can access resources behind VPN... It works, but I have no idea if it's good or bad...
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