the best way to connect docker-compose's app, db with vpn

Viewed 40

i wanna connect app, db wiht nordvpn. so i'm using this docker-compose and it works. but in this way, invidious(app) connected with vpn but invidious-db(postgres) don't connect network with vpn. is there way to connect invidious-db with vpn? or postgres don't communicate with external network? so i don't need to modify this docker-compose?(sorry for my ignorance but i don't know what postgres do exactly.) thank you.

version: "3"
services:

  vpn:
    image: azinchen/nordvpn:0.9.6
    network_mode: bridge
    cap_add:
      - NET_ADMIN     # Required
    devices:
      - /dev/net/tun     # Required
    ports:
      - "3000:3000"
    environment:
      - USER=username
      - PASS=password
      - COUNTRY=Japan
      - GROUP=Standard VPN servers
      - PROTOCOL=openvpn_udp
      - RANDOM_TOP=10
      - RECREATE_VPN_CRON=0 15 * * 6
      - OPENVPN_OPTS=--pull-filter ignore "ping-restart" --ping-exit 180
    restart: unless-stopped
    links:
      - invidious-db

  invidious:
    image: quay.io/invidious/invidious:latest
    network_mode: service:vpn
    environment:
      # Please read the following file for a comprehensive list of all available
      # configuration options and their associated syntax:
      # https://github.com/iv-org/invidious/blob/master/config/config.example.yml
      INVIDIOUS_CONFIG: |
        db:
          dbname: invidious
          user: kemal
          password: kemal
          host: invidious-db
          port: 5432
        check_tables: true
        popular_enabled: false
        statistics_enabled: true
        registration_enabled: false
        default_user_preferences:
          default_home: "Trending"
          feed_menu: ["Trending", "Subscriptions", "Playlists"]
    healthcheck:
      test: wget -nv --tries=1 --spider http://127.0.0.1:3000/api/v1/comments/jNQXAC9IVRw || exit 1
      interval: 30s
      timeout: 5s
      retries: 2
    depends_on:
      - invidious-db
      - vpn
    restart: unless-stopped

  invidious-db:
    image: docker.io/library/postgres:14
    network_mode: bridge
    volumes:
      - postgresdata:/var/lib/postgresql/data
      - ./config/sql:/config/sql
      - ./docker/init-invidious-db.sh:/docker-entrypoint-initdb.d/init-invidious-db.sh
    environment:
      POSTGRES_DB: invidious
      POSTGRES_USER: kemal
      POSTGRES_PASSWORD: kemal
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"]
    restart: unless-stopped

volumes:
  postgresdata:
0 Answers
Related