Docker-openvpn: How to connect to host or other containers through vpn

Created on 20 Sep 2017  路  3Comments  路  Source: kylemanna/docker-openvpn

Hi,
it may sound weird but I have no idea how to use the openvpn to connect to the host (of the openvpn docker container) or other containers. I thought that would automatically work since the container got NET_ADMIN.

Most helpful comment

To connect to other containers you need to have the openvpn container and the others on the same Docker network.

The best is to create one new Docker network (e.g. bridge) and to attach both the openvpn and the other containers to it. Example:

docker network create --attachable=true --driver=bridge --subnet=172.19.0.0/24 --gateway=172.19.0.1 ovpn-network

Then you can attached containers by doing docker network connect ovpn-network <container-name>, or by running your container on this network docker run (...) --net ovpn-network (...) <image-name>.

Of course in order for the client to know they can route package to the ovpn-network subnet, they need there static route updated. The OpenVPN client can do so for them. During the generation of the server simply do:

ovpn_genconfig -u udp://VPN.SERVERNAME.COM -p "route 172.19.0.0 255.255.255.0"

All 3 comments

To connect to other containers you need to have the openvpn container and the others on the same Docker network.

The best is to create one new Docker network (e.g. bridge) and to attach both the openvpn and the other containers to it. Example:

docker network create --attachable=true --driver=bridge --subnet=172.19.0.0/24 --gateway=172.19.0.1 ovpn-network

Then you can attached containers by doing docker network connect ovpn-network <container-name>, or by running your container on this network docker run (...) --net ovpn-network (...) <image-name>.

Of course in order for the client to know they can route package to the ovpn-network subnet, they need there static route updated. The OpenVPN client can do so for them. During the generation of the server simply do:

ovpn_genconfig -u udp://VPN.SERVERNAME.COM -p "route 172.19.0.0 255.255.255.0"

To have all clients work with the route, add push "route 172.19.0.0 255.255.255.0" to your server openvpn.conf.

Configuration suggested by @jcberthon works only in the case when the created bridge network is an exclusive network connected to openvpn container (since NAT is configured for one interface only). See #182.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rgarrigue picture rgarrigue  路  3Comments

breznak picture breznak  路  7Comments

arukaen picture arukaen  路  6Comments

josjaf picture josjaf  路  5Comments

yadaom picture yadaom  路  4Comments