docker - 为 VPN 容器连接的 docker 容器打开端口

标签 docker docker-compose vpn

我想通过 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.

最佳答案

我认为发布端口在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

The port forwarding takes place with the VPN container, not the one that reuses its IP stack.

port publishing and the container type network mode

关于docker - 为 VPN 容器连接的 docker 容器打开端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62615188/

相关文章:

node.js - Docker:未找到 npm

docker-compose - 如何指定要在 docker-compose 版本 3 中使用的容器运行时?

postgresql - Docker dpage/pgadmin4错误:指定的用户不存在

docker - docker run hello-world中的错误(守护程序的错误响应:OCI运行时创建失败:)

docker - 来自运行容器的新docker镜像不包含更新的值

docker - 在 Docker 中安装 Mongo c 和 c++ 驱动程序

json - Spring Boot应用程序可以在IntelliJ中运行,但不能作为Docker容器运行

kubernetes - Minikube服务接入本地VPN

Javascript - 从不同国家发送单个http请求

linux - 无法在 Linux 中连接 cloudflare warp vpn