Docker Error " FATAL: role "postgres" does not exist"
I was creating the database for my user service using using docker and bumped into this error
FATAL: role "postgres" does not exist
These where the logs.
[+] Running 1/1
✔ Container postgres-db Recreated 0.6s
Attaching to postgres-db
postgres-db |
postgres-db | PostgreSQL Database directory appears to contain a database; Skipping initialization
The last line of the log had the insight that helped me find the solution. I had database already created in pre-existing volume so docker skipped initialization. But I changed the user and password for the database in my docker-compose file. These changes did not reflect on my database directory since it was already created.
First step i took was to try remove the containers and the volume using
docker compose down -v
but instead i got this logs
abrahamnyagar@fedora:~/IdeaProjects/E_COMMERCE_BACKEND$ docker compose down -v
[+] Running 3/3
✔ Container postgres-db Removed 0.0s
! Volume e_commerce_backend_postgres_data Resource is still in use 0.0s
✔ Network e_commerce_backend_default Removed 0.3s
abrahamnyagar@fedora:~/IdeaProjects/E_COMMERCE_BACKEND$
To remove the volume which comtained the database i had to first kill the container. If you stop the container the volume remains attached and can be remove
Thus if you got the same issue run the commands
docker rm <container-name>
to remove container
Then
docker volume rm <volume-name>
to remove the assosiated volume hence database.
That it , the next time you run docker compose up everything will be initialized.