【问题标题】:Docker Containers with different Network Interface具有不同网络接口的 Docker 容器
【发布时间】:2017-03-30 15:15:30
【问题描述】:

问题: 我想在 Docker 容器中运行多个 VPN 服务器,每个服务器都有自己的公共 IP。

使用 -p 参数,我可以分别连接到每个接口,但我看到的公共 ip 是 eth0 接口,而不是我想要的接口 (eth0:1),所以我如何创建一个新的 docker0使用 eth0:1 作为流量接口的接口?

最好的问候和感谢。

【问题讨论】:

    标签: networking docker vpn docker-networking


    【解决方案1】:

    Docker 不使用它之外的网络。 对于主机与外部容器之间的连接,请使用端口绑定。 创建 docker 镜像时暴露 Dockerfile 中的端口 将 Docker 容器暴露给主机: 暴露容器对于主机识别容器运行在哪个端口非常重要。 docker run 命令中的 -p 用于公开端口。 语法: docker run -p host_ip:host_port:container_port image_name 例如, docker run -itd -p 192.168.134.122:1234:1500 image_name
    这会将容器的 1500 端口绑定到主机 192.168.134.122 上的 1234 端口。
    使用iptables查看网络进程——iptables -L -n -t nat

      Now the request send to host_ip (192.168.134.122) and port (1243) is redirect to container with ip (172.17.0.2) and port (1500).
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多