Containers and VPNs

Force a Container to use a VPN

Force a Container to use a VPN

Force Docker Containers to use a VPN

I wanted to clear up the steps a bit, as my original set is a bit convoluted. I made it more complicated (slightly) than it has to be, and figure there is an easier way.

The following is based on using Portaianer-CE as a front end GUI (Graphical User Interface) for editing, interacting with, and deploying Docker-CE containers.  To install Portainer-CE (at the time of this writing), you can run the following two commands for docker:

Now go to your Docker host IP address at port 9000 ( http://my-host.local:9000) and login for the first time.  Select Docker, and Local, and you'll be brought to a dashboard where you can select the Containers option.  You should see all of your running docker containers in the User interface.

Updated steps

  1. Setup and get your desired VPN container.  Ensure the VPN starts and maintains a connection when it's started.  
  2. Stop your other containers that you want to run through your VPN container, and make note of any port mappings in those containers.
  3. Edit your VPN container by adding the same port mappings to it, as you have in the stopped containers you want to run through the VPN container.
  4. Re-deploy your VPN container with the new port mappings.
  5. Edit the containers you want to use the VPN container, and remove the port mappings from them.
  6. Now go to the Network settings of those containers, and select "Container", then in the next drop down select your running VPN container.
  7. Re-deploy the updated containers.
  8. Once up and running, simply test that you can still reach your containerized applications as you did before making these changes.

Voila! You are now forcing your containers to use the VPN container network.