Not sure which postgres image are you using.
If you look at the official postgres image for complete information. It allows user to specify the environment variables for the below ones and these can be easily overridden at run time.
- POSTGRES_PASSWORD
- POSTGRES_USER
- PGDATA
- POSTGRES_DB
- POSTGRES_INITDB_ARGS
Environment variables can be overridden using below three methods depending on your case.
- Run Image: If running docker image directly, use below to include environment variable in
docker runwith-e K=V. Please refer documentation for more details here
docker run -e POSTGRES_PASSWORD=secrect -e POSTGRES_USER=postgres <other options> image/name
- Dockerfile: If you need to specify the environment variable in
Dockerfile, specify as mentioned below. Please refer documentation for more details here
ENV POSTGRES_PASSWORD=secrect
ENV POSTGRES_USER=postgres
- docker-compose: If you need to specify the environment variable in
docker-compose.yml, specify as below. Please refer documentation for more details here
web:
environment:
- POSTGRES_PASSWORD=secrect
- POSTGRES_USER=postgres
Hope this is useful.
Answer from Rao on Stack OverflowNot sure which postgres image are you using.
If you look at the official postgres image for complete information. It allows user to specify the environment variables for the below ones and these can be easily overridden at run time.
- POSTGRES_PASSWORD
- POSTGRES_USER
- PGDATA
- POSTGRES_DB
- POSTGRES_INITDB_ARGS
Environment variables can be overridden using below three methods depending on your case.
- Run Image: If running docker image directly, use below to include environment variable in
docker runwith-e K=V. Please refer documentation for more details here
docker run -e POSTGRES_PASSWORD=secrect -e POSTGRES_USER=postgres <other options> image/name
- Dockerfile: If you need to specify the environment variable in
Dockerfile, specify as mentioned below. Please refer documentation for more details here
ENV POSTGRES_PASSWORD=secrect
ENV POSTGRES_USER=postgres
- docker-compose: If you need to specify the environment variable in
docker-compose.yml, specify as below. Please refer documentation for more details here
web:
environment:
- POSTGRES_PASSWORD=secrect
- POSTGRES_USER=postgres
Hope this is useful.
I think the postgres user and password is being set on entrypoint, like in line 23 on official image entrypoint.
https://github.com/docker-library/postgres/blob/e4942cb0f79b61024963dc0ac196375b26fa60dd/9.6/docker-entrypoint.sh
Can you check your entrypoint?
How to change the postgresql password within docker
How to pass default user and password (postgres) to docker start
postgresql - Docker: you must specify POSTGRES_PASSWORD - Stack Overflow
How to create postgres superuser role and DB on docker-compose.yml
Hello, I recently got into working within docker and postgresql and I was wondering how I can change the login info for postgresql within docker as I don't have the postgresql files within my PC and can't change it through the pg_hba_conf file method and couldn't find out how to do after looking into the problem and was curious if anyone on this sub had a clue on how to solve it?