Jonathan
Jonathan

Reputation: 41

Docker-compose scale command creates random ports for new containers

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

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

Upvotes: 1

Views: 3533

Answers (1)

Thomas Schwärzl
Thomas Schwärzl

Reputation: 9917

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.

Upvotes: 3

Related Questions