Home > Enterprise >  Change port parameters used by a database in Docker without updating the image?
Change port parameters used by a database in Docker without updating the image?

Time:04-18

I want to change the database port from the postgres docker image. The following properly opens the port 5000 but does not do the first step of telling postgres to start on a non-default port :

docker run -it -p 5000:5000 --env POSTGRES_DB=mydb --env POSTGRES_PASSWORD=mypw --env POSTGRES_USER=myuser my.company.repo/postgres:11-alpine

Do I need to create my own image that does

from my.company.repo/postgres:11-alpine
# some command to change the pg port to 5000

Is there another way to simply change the postgres port?

Update Thinking on this.. i'm guessing the way to do it is to ensure the docker image is expecting POSTGRES_PORT as an environment variable. If not the image has to be changed..

CodePudding user response:

Instead of changing the port that PostgreSQL uses you can just map the host port you want to use to the default port in the container (5432)

docker run -p 5000:5432 ...
  • Related