docker - 如何将静态公共(public) IP 分配给 docker 容器

标签 docker

有没有办法将静态公共(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/

相关文章:

ruby-on-rails - Docker-compose:在SIGTERM之后关闭端口

r - 使用 docker 多阶段构建进行 R 开发和部署设置

docker - 由节点Alpine和mysql构建的Docker-compose推送镜像

docker - 这个 Dockerfile 是如何在没有入口点或 cmd 的情况下实际运行 logstash 的?

node.js - Dockerfile 公开 Node.js 镜像的端口

java - Rabbitmq 连接被拒绝,在 Linux 服务器上的 docker 容器内运行

containers - 如何在启动时在boot2docker中自动启动容器?

docker - 在 docker 容器中运行 systemd 导致主机崩溃

git - .dockerignore 所有子文件夹但不包括文件夹本身中的文件

docker - 如何防止 minikube 集群在启动时运行?