问题
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