有没有办法将静态公共(public)IP
分配给容器。所以容器有公网IP。客户端可以通过IP访问容器。
最佳答案
现在应该可以使用 docker 1.10 和 new docker run --ip
option您现在在 docker network connect
中看到的.
If specified, the container's IP address(es) is reapplied when a stopped container is restarted. If the IP address is no longer available, the container fails to start.
One way to guarantee that the IP address is available is to specify an
--ip-range
when creating the network, and choose the static IP address(es) from outside that range. This ensures that the IP address is not given to another container while this container is not on the network.
$ docker network create --subnet 172.20.0.0/16 --ip-range 172.20.240.0/20 multi-host-network
$ docker network connect --ip 172.20.128.2 multi-host-network container2
另见 Jessie Frazelle的博文“IPs for all the Things”,以及拉取请求 docker/docker#19001 .
关于docker - 如何将静态公共(public) IP 分配给 docker 容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34688906/