The published ports need to be on the vpnclient container. The app container is not in control of the network namespace of the vpnclient container, it just attaches itself to it.
Hmm, doesn’t make sense to me. Are you sure there is no firewall configured that prevents the traffic?
The way you start the vpn container is correct. You should be able to access the container port 8080 through the host port 8080, regardless in which of both containers the actual process is running.
Yes, the port needs to be open on the vpn container, but there’s also another change to make.
The vpn inside the container sees 172.17.0.0/16 as the local lan, so 192.168.0.0/24 is pushed over the vpn, and that’s a problem.
After I added route add -net 192.168.0.0/24 dev eth0 in the vpn container everything works.
Any vpn that pushes a default gw would create the same issue, as the LAN subnet outside the container would not be known to the vpn client.
If we look at the routing table inside the vpn container we see that openvpn creates 2 rules: a new default gw at the top, and an exception for the vpn remote.
That’s why route add -net 192.168.0.0/24 dev eth0 works, it adds another exception to the standard openvpn routing table to avoid sending your local lan outside the container to the vpn remote.
# ip r
0.0.0.0/1 via 10.10.10.1 dev tun0
default via 172.17.0.1 dev eth0
104.29.234.12 via 172.17.0.1 dev eth0
172.17.0.0/16 dev eth0 proto kernel scope link src 172.17.0.2
You can replicate using alpine as vpn client with these commands:
RUN apk --no-cache --no-progress upgrade
RUN apk --no-cache --no-progress add openvpn
CMD /usr/sbin/openvpn --config /config/client.ovpn
any generic openvpn configuration that pushes a default gw would do.
I know plenty of people that use the bubuntux/nordvpn image and the container takes care of this, without them having to manually add routes. This is why I still believe it depends on the image and/or vpn client software inside the container.
Anyway, thank you for sharing your solution and explaining it in detail!