Closed AlexSSP closed 1 year ago
@AlexSSP why did you close this? Did you find the issue?
I'd guess that this stems from POSTGRES_DB
being different than the POSTGRES_USER
. If you use the postgres
cli (and I'd assume many libraries), then if you don't specify which database to connect to, it will default to using a database named after the specified user.
$ docker run -it --rm -e 'POSTGRES_PASSWORD=5678' -e 'POSTGRES_USER=not-postgres' -e 'POSTGRES_DB=foo' --name pg postgres:16
...
2024-04-08 21:12:28.704 UTC [1] LOG: database system is ready to accept connections
2024-04-08 21:13:26.690 UTC [75] FATAL: database "not-postgres" does not exist
$ # in another terminal
$ docker exec -it pg psql --username not-postgres
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: database "not-postgres" does not exist
$ docker exec -it pg psql --username not-postgres --dbname foo
psql (16.2 (Debian 16.2-1.pgdg120+2))
Type "help" for help.
foo=#
\q
Hello! When I put in my environment of docker-compose file
image: postgres:15.3-alpine
environment:
POSTGRES_DB: arm-bd-db
POSTGRES_USER: armkdbd
POSTGRES_PASSWORD: armkdbd_password
container started, database arm-bd-db created, but i see in my docker container logFATAL: database "armkdbd" does not exist.
Why is this happening?