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.
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.
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:
Then you can attached containers by doing
docker network connect ovpn-network <container-name>, or by running your container on this networkdocker run (...) --net ovpn-network (...) <image-name>.Of course in order for the client to know they can route package to the
ovpn-networksubnet, they need there static route updated. The OpenVPN client can do so for them. During the generation of the server simply do: