Docker Community Forums

Share and learn in the Docker community.

How to set up containers with VPN client installed, each connecting to another VPN server?

For a project, I have to connect to more than one environment on the same server. That’s why I want to use containers. I will install VPN clients in each container and connect to different networks with these clients. When I will connect to devices in these networks, I will connect through these containers. Is it possible to do this? How is it done?

Using this parameter it’s possible to tell a container to use the network of another. You can run an OpenVPN client container, which will initiate a secure connection, and configure other containers to use its network. The beauty of this setup is that you don’t need to learn or manage any complicated ip_tables rules or any other network configuration, you can just point one container at another and have the traffic secured.

All I needed now was a suitable Docker image. Eventually, I got lucky and found an image that supported my exact VPN provider, NordVPN.

This is how I created and started the OpenVPN container. Once this was running, a secure VPN connection was established to NordVPN.

docker run
–name vpn
–cap-add=NET_ADMIN
–device /dev/net/tun
-p 9117:9117
-e NETWORK=192.168.1.0/24
-e USER=username
-e PASS=‘password’
bubuntux/nordvpn
Most of these options are standard, but the -p 9117:9117 parameter on line 5 needs explanation. This is the port mapping that Jackett uses by default. When we use another container’s network it’s necessary to expose the port(s) that our other containers use on the VPN container.

And here is how I setup Jackett to use the VPN container. The relevant line is --net=container:vpn. Note that I don’t have a -p 9117:9117 line here like I would if I was not using --net=container:vpn.

docker run
–name=jackett
–restart unless-stopped
-e PUID=1000
-e PGID=1000
-e TZ=Europe/London
–net=container:vpn
-v /opt/appdata/jackett:/config
-v /opt/appdata/jackett/downloads:/downloads
linuxserver/jackett
Now I can access Jackett at http://:9117 and all traffic will be sent through the VPN container’s network!

Hi,

Thanks for detailed explanation. But i need something else. I have more than 1 containers, each connected to different VPN servers. When I want to access a device which is located in VPN A’s network, I want to use connect device from host server through VPN A container. When I want to access a device which is located in VPN B’s network, I want to use connect device from host server through VPN B container. Is it possible?

Hi there! I know that it seems to be not a good idea but sometimes I look for the information I need on websites the usual user does not have an access to. I use dark web vpn for that. So, I hope that would be useful for you if you need more information than you can get from the normal web.