1

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

2 Answers 2

7
-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]

Sign up to request clarification or add additional context in comments.

2 Comments

are they not going to fight over the same tcp?
No. The port of the machine is what involves in the conflict. As long as you make it different. It works.
2

@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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.