Containers and VPNs
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.
- Setup and get your desired VPN container. Ensure the VPN starts and maintains a connection when it's started.
- Stop your other containers that you want to run through your VPN container, and make note of any port mappings in those containers.
- 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.
- Re-deploy your VPN container with the new port mappings.
- Edit the containers you want to use the VPN container, and remove the port mappings from them.
- Now go to the Network settings of those containers, and select "Container", then in the next drop down select your running VPN container.
- Re-deploy the updated containers.
- 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.