I have an application container (app) connected to the internet via a VPN-container (vpn). While that connectivity works, the app container is now unable to connect to the database container (db).
Is there a way to have the app container connect to local containers (or any RFC1918 address) while simultaneously also connected through the vpn? I would simply add db to the same network_mode but the db very specifically needs to be accessible by another container not connected through the vpn (A second application that will read from db).
The VPN container is running bubuntux/nordvpn and my docker-compose.yml is as follows:
version: "3.9"
services:
app:
build: app/
depends_on:
- db
network_mode: service:vpn
depends_on:
- vpn
db:
image: postgres:alpine
restart: always
network_mode: service:vpn
environment:
POSTGRES_USER: PASSWORD
POSTGRES_PASSWORD: PASSWORD
POSTGRES_DB: PASSWORD
vpn:
image: bubuntux/nordvpn
cap_add:
- NET_ADMIN
- SYS_MODULE
sysctls:
- net.ipv4.conf.all.rp_filter=2
devices:
- /dev/net/tun
environment:
- USER=EMAIL@EMAIL.COM
- "PASS=PASSWORD"
- CONNECT=United_States
- TECHNOLOGY=NordLynx
ulimits:
memlock:
soft: -1
hard: -1
I have attempted to use link, as follows:
app:
links:
- db
However, I get a startup error, specifically that container type network can't be used with links.
To restate the question: How do I have a container connected to the internet through a VPN container (In this case bubuntux/nordvpn) that is also accessible by non-VPN connected containers?
Thank you!