Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker container and host network VPN

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..

like image 598
Capacytron Avatar asked Nov 24 '15 21:11

Capacytron


People also ask

Can a Docker container use a VPN?

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.

Does Docker container have same IP as host?

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.

Does Docker use host network?

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.

Can Docker containers access local network?

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.


2 Answers

I had to restart docker after connecting host machine to VPN.

sudo systemctl restart docker docker start {name-of-container}

like image 148
Kennethz3 Avatar answered Sep 29 '22 17:09

Kennethz3


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...

like image 35
Capacytron Avatar answered Sep 29 '22 17:09

Capacytron