Docker-compose scale命令为新容器创建随机端口 [英] Docker-compose scale command creates random ports for new containers
本文介绍了Docker-compose scale命令为新容器创建随机端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当前docker-compose scale命令为新容器创建随机端口.
Currently docker-compose scale command creates random ports for the new containers.
是否可以为新容器指定端口?
Is there a way to specify a port for the new containers?
推荐答案
在您的docker-compose.yml
中,
postgres:
image: postgres:9.5
environment:
- POSTGRES_PASSWORD=postgres
ports:
- 5432:5432
它将绑定到5432
,但是,请注意,出于明显的原因,您在同一节点上不能有多个实例.
it will bind to 5432
, however, note that you can't have more than one instance on the same node for obvious reason.
要在一个节点上使用多个实例,可以使用这样的动态端口
To use multiple instances on one node you can use dynamic ports like this
postgres:
image: postgres:9.5
environment:
- POSTGRES_PASSWORD=postgres
ports:
- 5432+:5432
从而允许scale=4
创建在5432
,5433
,5434
,5435
上发布的4个实例,但是所有实例都路由到其内部端口.
Thus allowing the scale=4
to create 4 instances published on 5432
, 5433
, 5434
, 5435
, but all routing to their internal ports.
这篇关于Docker-compose scale命令为新容器创建随机端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文