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.
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.
Now I can access Jackett at http://:9117 and all traffic will be sent through the VPN container’s network!
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?