Jim
Jim

Reputation: 1141

running two docker postgres service

I'm trying to run two postgres database with Docker service. I know they can't run on the same time, so I would like to change the port (not the -p 5433: 5432)

here's my script to start the docker service:

docker service create --name account-db --network account -e POSTGRES_PASSWORD=secret_password -p 5432:5432 -d --mount type=volume,source=account,target=/var/lib/postgresql/data postgres:latest

so if I want to run one on 5432 and another on 5433, how should I achieve that? thanks for any input / suggestion

Upvotes: 1

Views: 7534

Answers (2)

Vamsi
Vamsi

Reputation: 684

-p 5432:5432

This is the port mapping for the container. So for the first service, it should be

-p 5432:5432

And for the second service it should be

-p 5433:5432

The syntax is -p [port of the machine] : [port of the container]

Upvotes: 7

Shahriar
Shahriar

Reputation: 13804

@vamsi is right.

But when you are using a node port xxxx, you need to make sure that xxxx is available.

-p xxxx:5432

If you want to assign a free port automatically, use this

-p :5432

Leave node port empty :5432

Upvotes: 2

Related Questions