I am not able to login into my postgres databse deployed in docker. PFB my docker-compose.yml
discountdb:
image: postgres
docker-compose.override.yml
discountdb:
container_name: discountdb
environment:
- POSTGRES_USER=admin
- POSTGRES_PASSWORD=admin1234
- POSTGRES_DB=DiscountDb
restart: always
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data/
When I am trying to create server from pgAdmin4, I am getting the following error
Following is the db logs
What did I miss?
3
Answers
The issue was with my postgres_data volume. I removed the volume using the command
then ran the docker-compose again which resolved the issue.
The environment variables you set are only used if Postgres can’t find an existing database when then container starts.
Since you map a docker volume to
/var/lib/postgresql/data/
, chances are that you already have a database with existing users defined.Try removing the volume mapping, so you’re sure that Postgres creates a fresh database. If that solves it, then you have two options:
Nothing is wrong here but the POSTGRES_PASSWORD is taken into account the first time you start the container I mean when your postgres_data folder is still empty. If you changed the password but postgres_data is not empty the new password is ignored, you must log in with the first one.