Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running PostgreSQL docker image on a different Port


I'm trying to run a PostgreSQL instance on a different port, by setting the port as argument in '-p' however it does not seem to have any effect. Ex:

docker run --name db_Dev -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=postgresDev -p 7432:7432 postgres:10.5

Output:

2019-09-15 17:50:29.494 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2019-09-15 17:50:29.494 UTC [1] LOG:  listening on IPv6 address "::", port 5432

Any idea how to set a different port for it? Thanks

like image 237
Francesco Marchioni Avatar asked Sep 15 '19 17:09

Francesco Marchioni


1 Answers

If you want to run multiple Postgres instances or change the listening port of Postgres then follow this.

docker run --name db_Dev -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=postgresDev -p 7432:5432 postgres:10.5

Here -p 7432:5432 is mapping port 5432 inside your Postgres container on to port 7432 of your host.

Or you can change the listening port 5432 of Postgres by setting environment variable PGPORT to 7432.

docker run --name db_Dev -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=postgresDev -e PGPORT=7432 -p 7432:7432 postgres:10.5

Note: If PGPORT doesn't work try POSTGRES_PORT.

like image 187
mchawre Avatar answered Nov 03 '22 21:11

mchawre