Docker-compose scale command creates random ports

2019-08-22 09:15发布

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条回答
甜甜的少女心
2楼-- · 2019-08-22 09:57

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.

查看更多
登录 后发表回答