Docker-compose scale command creates random ports for new containers

…衆ロ難τιáo~ 提交于 2019-12-24 19:16:19

问题


Currently docker-compose scale command creates random ports for the new containers.

Is there a way to specify a port for the new containers?


回答1:


In your docker-compose.yml,

postgres:
  image: postgres:9.5
  environment:
    - POSTGRES_PASSWORD=postgres
  ports:
    - 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

Thus allowing the scale=4 to create 4 instances published on 5432, 5433, 5434, 5435, but all routing to their internal ports.



来源:https://stackoverflow.com/questions/49768685/docker-compose-scale-command-creates-random-ports-for-new-containers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!