Docker Community Forums

Share and learn in the Docker community.

Docker Compose - Connecting Networks

Greetings,

I have docker compose (gluetun) - which is a VPN container

---
version: '2.4'
services:
  gluetun:
    image: qmcgaw/gluetun
    container_name: gluetun
    environment:
      - PUID=1029
      - PGID=100
      - VPNSP=private internet access
      - REGION=CA Ontario
      - OPENVPN_USER=#### #Change to YOUR Username
      - OPENVPN_PASSWORD=###### #Change to YOUR Password
    volumes:
      - /volume1/docker/gluetun/config:/gluetun
    ports:
      - 19999:19999 #Netdata
      - 9080:9080 #QBitTorrent Web-UI
      - 6881:6881 #QBitTorrent
      - 6881:6881/udp #QBitTorrent
    cap_add:
      - NET_ADMIN
    restart: unless-stopped

if I have another container that I want to use the first one as it’s main network to use the VPN connection, what I am supposed to change/add in the other docker container compose file?

Here is the default container yml for my second container

---
version: "2"
services:
  heimdall:
    image: linuxserver/heimdall
    container_name: heimdall
    environment:
      - PUID=1024
      - PGID=100
      - TZ=America/Toronto
    volumes:
      - /volume1/docker/Heimdall/config:/config
    ports:
      - 555:80
      - 4455:443
    restart: unless-stopped

Note:
It says in the guide to use the following line to connect, but how exactly it should look like

Container in another docker-compose.yml

Add network_mode: "container:gluetun" to your docker-compose.yml , provided Gluetun is already running.

Thanks in advance.

Update:

I found the answer,

You just simply delete the ports from the second docker compose and add them to the first one

and just mention the 1st docker container network to the second.

So the first docker container should look like this

---
version: '2.4'
services:
  gluetun:
    image: qmcgaw/gluetun
    container_name: gluetun
    environment:
      - PUID=1029
      - PGID=100
      - VPNSP=private internet access
      - REGION=CA Ontario
      - OPENVPN_USER=##### #Change to YOUR Username
      - OPENVPN_PASSWORD=###### #Change to YOUR Password
    volumes:
      - /volume1/docker/gluetun/config:/gluetun
    ports:
      - 8080:80 #heimdall-VPN
      - 4433:443 #heimdall-VPN
    cap_add:
      - NET_ADMIN
    restart: unless-stopped

and the second will look like this

---
version: "2"
services:
  heimdall:
    image: linuxserver/heimdall
    container_name: heimdall-VPN
    network_mode: "container:gluetun"
    environment:
      - PUID=1024
      - PGID=100
      - TZ=America/Toronto
    volumes:
      - /volume1/docker/Heimdall/config:/config
    restart: unless-stopped