通过VPN容器连接的Docker容器开放端口

4
我想通过VPN运行一个docker容器(kmb32123/youtube-dl-server)以便访问地理位置被限制的内容。我找到了一个合适的VPN docker镜像(ilteoood/docker-surfshark)。我试图将这两个镜像合并到单个docker-compose.yml文件中。然而,由于冲突选项,我无法发布youtube-dl-server的端口。

冲突选项:端口发布和容器类型网络模式

是否有其他方法可以让youtube-dl-server通过docker-surfshark容器路由流量,同时仍在本地公开端口8080以便我可以访问它?

version: "2"

services: 
  surfshark-uk:
    image: ilteoood/docker-surfshark
    container_name: surfshark
    environment: 
        - SURFSHARK_USER=foo
        - SURFSHARK_PASSWORD=bar
        - SURFSHARK_COUNTRY=uk
        - CONNECTION_TYPE=udp
    cap_add: 
        - NET_ADMIN
    devices:
        - /dev/net/tun
    restart: unless-stopped
  youtube-dl-uk:
    image: "kmb32123/youtube-dl-server"
    container_name: yt-download-uk
    network_mode: container:surfshark-uk
    depends_on:
      - surfshark-uk
    ports:
      - 8080:8080
    volumes:
      - /Users/greg/Desktop/ukvids:/youtube-dl
    restart: unless-stopped

greg@computer docker $ docker-compose up
WARNING: Found orphan containers (surfshark, 949001ea6405_yt-download-uk) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up.
Creating surfshark-uk ... done
Creating yt-download-uk ... error

ERROR: for yt-download-uk  Cannot create container for service youtube-dl-uk: conflicting options: port publishing and the container type network mode

ERROR: for youtube-dl-uk  Cannot create container for service youtube-dl-uk: conflicting options: port publishing and the container type network mode
ERROR: Encountered errors while bringing up the project.
1个回答

2
我认为在surfshark-uk容器中发布端口将完成与youtube-dl-uk相同的工作,因为它使用surfshark-uk的网络。因此,当尝试访问时,该端口将在您的主机上可访问。
curl localhost:8080
yt-download-uk   | 172.26.0.1 - - [28/Jun/2020 02:03:17] "GET / HTTP/1.1" 404 720

所以更新docker-compose文件,它就会正常工作。
  surfshark-uk:
    image: ilteoood/docker-surfshark
    container_name: surfshark
    ports:
      - 8080:8080

端口转发是在 VPN 容器中进行的,而不是重用其 IP 栈的容器中进行的。 请参考 端口发布和容器类型网络模式

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接