Hey everyone! I'm not very experienced with this tech stuff, so I'm hoping you can help me out. I've got an application that needs to connect to an L2TP VPN to access a database using sqlcmd. Normally, I just activate the VPN on my PC, and it works perfectly.
Now, I'm trying to Dockerize my app and have most of it functioning, but I need to connect the Docker container to the VPN for my script to run as expected.
Does anyone know the best way to achieve this? I've come across some resources, like [this one](https://askubuntu.com/questions/1167283/l2tp-connection-client-on-ubuntu-18-04-server), but I'm unsure how to implement it in my Dockerfile.
2 Answers
You might want to check out existing VPN projects for Docker. A common approach is to run two containers: one for the VPN and one for your app. Then, configure your app container to use the network of the VPN container.
For example, using `network_mode: service:YourVPNcontainer` can allow your app to connect through the VPN. Just do a quick search, and you'll find plenty of resources tailored to your specific setup!
Another option is to connect the VPN to the host and set the container's network mode to 'host'. Just be cautious, as this approach has some security risks. It's generally not recommended unless you're fully aware of the implications. In most cases, you won't need to use `network_mode: host`.
... which has quite some risk in regards to security. Absolutely do not do this unless you are fully aware of the risks involved. Never use `network_mode: host` unless absolutely necessary!
Ah interesting, thanks! I'm mostly confused about what to include in my Dockerfile to make things work. I see many projects, but I don't know what leads to what or what I need to exclude/include in mine.