从本地网络访问在 VPN 后面运行的 Docker-Compose 服务

问题描述 投票:0回答:1

我正在尝试使用 docker-compose、wireguard VPN、qbittorrent 客户端以及最终的 sonarr/radarr 在 debian linux 机器上设置 plex 服务器。

当使用 docker-compose 在 VPN 容器后面运行时,我无法从本地网络的计算机访问 qbittorrent UI。这是我当前的 docker-compose 文件

name: media_server

services:
  vpn:
    image: lscr.io/linuxserver/wireguard:latest
    container_name: wireguard
    hostname: wireguard
    networks:
      wireguard_network:
        ipv4_address: 10.0.1.100
    cap_add:
      - NET_ADMIN
      - SYS_MODULE
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=America/New_York
    privileged : true
    volumes:
      - ./vpn_config:/config/wg_confs
    ports:
      - 58120:58120/udp # VPN Port
      - 8180:8180 # qbittorrent
      - 6881:6881 # qbittorrent
      - 6881:6881/udp # qbittorrent
    sysctls:
      - net.ipv4.conf.all.src_valid_mark=1
      - net.ipv6.conf.all.disable_ipv6=1
    restart: always

  qbittorrent:
    image: lscr.io/linuxserver/qbittorrent:latest
    container_name: qbittorrent
    depends_on:
      - vpn
    network_mode: service:vpn
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=America/New_York
      - WEBUI_PORT=8180
    restart: unless-stopped

  plex:
    image: lscr.io/linuxserver/plex:latest
    container_name: plex
    depends_on:
      - vpn
    network_mode: host
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=America/New_York
      - VERSION=docker
      - PLEX_CLAIM=*****
    volumes:
      - ./plex_config:/config
      - ./media/tv:/data/tv
      - ./media/movies:/data/movies
    ports:
      - 32400:32400
      - 1900:1900/udp
      - 5353:5353/udp
      - 8324:8324
      - 32410:32410/udp
      - 32412:32412/udp
      - 32413:32413/udp
      - 32414:32414/udp
      - 32469:32469
    restart: unless-stopped

networks:
  wireguard_network:
    ipam:
      driver: default
      config:
        - subnet: 10.0.1.0/24

使用此配置 - 如果我尝试连接到 http://:8180 我会超时

http://:32400 可以正常工作并显示 Plex UI(因为它不在 VPN 后面)

所有容器日志看起来都很好,没有错误

运行

curl ifconfig.me
返回以下内容

docker exec wireguard curl ifconfig.me
149.*.*.*

docker exec qbittorrent curl ifconfig.me
149.*.*.*

docker exec plex curl ifconfig.me
174.*.*.*

所以我知道 qbittorrent 流量正确地通过 VPN 路由 - 但我无法从本地网络访问 UI,这应该是可能的,我想实现这一点

我尝试更改图像和主机的 iptables 并启用

net.ipv4.ip_forward
- 但我似乎无法从本地网络访问 UI

如果我在wireguard_network之外运行qbittorrent容器,我可以像Plex一样访问它

理想情况下,我也想将 plex 放在 VPN 后面并使其可访问,但我认为没有必要

如有任何帮助,我们将不胜感激!

docker networking docker-compose vpn plex
1个回答
0
投票

我相信将VPN设置为使用network_mode:host可以实现我想要的

拉取 Firefox 图像以便能够检查诸如 Whatsmyip 之类的网站,我可以看到流量正在流经我的 VPN,并且与

docker exec qbittorrent curl ifconfig.me
返回的内容相匹配

name: media_server

services:
  vpn:
    image: lscr.io/linuxserver/wireguard:latest
    container_name: wireguard
    hostname: wireguard
    network_mode: host
    cap_add:
      - NET_ADMIN
      - SYS_MODULE
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=America/New_York
    privileged : true
    volumes:
      - ./vpn_config:/config/wg_confs
      - ./scripts:/scripts
    ports:
      - 58120:58120/udp # VPN Port
      - 8180:8180 # qbittorrent
      - 6881:6881 # qbittorrent
      - 6881:6881/udp # qbittorrent
      - 32400:32400 # plex
      - 1900:1900/udp # plex
      - 5353:5353/udp # plex
      - 8324:8324 # plex
      - 32410:32410/udp # plex
      - 32412:32412/udp # plex
      - 32413:32413/udp # plex
      - 32414:32414/udp # plex
      - 32469:32469 # plex
        # sysctls:
        #- net.ipv4.conf.all.src_valid_mark=1
        #- net.ipv6.conf.all.disable_ipv6=1
    restart: always

  qbittorrent:
    image: lscr.io/linuxserver/qbittorrent:latest
    container_name: qbittorrent
    depends_on:
      - vpn
    network_mode: service:vpn
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=America/New_York
      - WEBUI_PORT=8180
    restart: unless-stopped

  plex:
    image: lscr.io/linuxserver/plex:latest
    container_name: plex
    depends_on:
      - vpn
    network_mode: service:vpn
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=America/New_York
      - VERSION=docker
      - PLEX_CLAIM=claim-*****
    volumes:
      - ./plex_config:/config
      - ./media/tv:/data/tv
      - ./media/movies:/data/movies
    restart: unless-stopped

  firefox:
    image: lscr.io/linuxserver/firefox:latest
    container_name: firefox
    depends_on:
      - vpn
    network_mode: service:vpn
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Etc/UTC
© www.soinside.com 2019 - 2024. All rights reserved.