You most probably started the container without the env variables set. The db was then initialized without user or DB info.

You need to delete the volume and try again.

Credit: https://github.com/docker-library/postgres/issues/453#issuecomment-393939412

Answer from howaryoo on Stack Overflow
Discussions

User and database not created with docker-compose
The docs explain that you can make ... user and database on creation, using environment variables. I can't seem to make that work using docker-compose: # docker-compose.yml services: postgresql: image: postgres:alpine environment: POSTGRES_DB: iotplatform POSTGRES_USER: iotplatform POSTGRES_PASSWORD: iotplatform ... docker-compose up -d --force-recreate postgresql docker-compose exec postgresql psql -U iotplatform # psql: FATAL: role "iotplatform" does not exist... More on github.com
🌐 github.com
21
December 17, 2018
postgresql - Docker - "FATAL: database does not exist" - Stack Overflow
I'm running into the following issue when trying to run an app in docker with docker-compose. Judging from other posts here on SO, my docker-compose.yml file looks correct (which seems to be causin... More on stackoverflow.com
🌐 stackoverflow.com
February 10, 2022
Role "postgres" does not exist
I am trying to connect a Django ... like the database is not created with the correct user in my docker-compose.yml file. I get the following error: gestion_materiel_tps-db-1 | 2023-03-06 08:19:53.351 UTC [70] FATAL: password authentication failed for user "postgres" gestion_materiel_tps-db-1 | 2023-03-06 08:19:53.351 UTC [70] DETAIL: Role "postgres" does not exist... More on github.com
🌐 github.com
5
March 6, 2023
with docker-compose.yml "Root or postgres or any role does not exist", postgres, postgrest, swagger connect to db
Hi, i'm new to docker and need your help .. i just cant find any solution. Trying to connect to the DB via docker-compse.yml. C:\Users\iso01>docker ps CONTAINER ID IMAGE COMMAND CREATED STAT... More on github.com
🌐 github.com
13
August 26, 2020
🌐
GitHub
github.com › langgenius › dify › issues › 8147
database "postgres" does not exist · Issue #8147 · langgenius/dify
September 9, 2024 - docker-db-1 | 2024-09-09 08:39:55.421 UTC [47] FATAL: database "postgres" does not exist docker-db-1 | 2024-09-09 08:40:07.395 UTC [126] FATAL: no pg_hba.conf entry for host "172.18.0.6", user "postgres", database "dify", no encryption docker-worker-1 | ERROR [root] Database migration failed, error: (psycopg2.OperationalError) connection to server at "db" (172.18.0.5), port 5432 failed: FATAL: no pg_hba.conf entry for host "172.18.0.6", user "postgres", database "dify", no encryption
Author   langgenius
🌐
GitHub
github.com › wallabag › docker › issues › 328
Postgres error database does not exist · Issue #328 · wallabag/docker
April 22, 2023 - I use wallabag in docker. After an recent update the connection to the existing and before used postgresql database can't be established any more. The error message is just "database &quot...
Author   wallabag
🌐
GitHub
github.com › docker-library › postgres › issues › 537
User and database not created with docker-compose · Issue #537 · docker-library/postgres
December 17, 2018 - The docs explain that you can make ... user and database on creation, using environment variables. I can't seem to make that work using docker-compose: # docker-compose.yml services: postgresql: image: postgres:alpine environment: POSTGRES_DB: iotplatform POSTGRES_USER: iotplatform POSTGRES_PASSWORD: iotplatform ... docker-compose up -d --force-recreate postgresql docker-compose exec postgresql psql -U iotplatform # psql: FATAL: role "iotplatform" does not exist...
Author   docker-library
🌐
Stack Overflow
stackoverflow.com › questions › 71059557 › docker-fatal-database-does-not-exist
postgresql - Docker - "FATAL: database does not exist" - Stack Overflow
February 10, 2022 - This is the docker setup used at my current work, and it works for everyone else in the team besides me. I'm the only one in an OSX environment though. Env variables are passed via a .env file. POSTGRES_MULTIPLE_DATABASES: github.com/mrts/docker-postgresql-multiple-databases
🌐
GitHub
github.com › docker-library › postgres › issues › 1055
Role "postgres" does not exist · Issue #1055 · docker-library/postgres
March 6, 2023 - I am trying to connect a Django server to a PSQL database but it seems like the database is not created with the correct user in my docker-compose.yml file. I get the following error: gestion_materiel_tps-db-1 | 2023-03-06 08:19:53.351 UTC [70] FATAL: password authentication failed for user "postgres" gestion_materiel_tps-db-1 | 2023-03-06 08:19:53.351 UTC [70] DETAIL: Role "postgres" does not exist.
Author   docker-library
🌐
GitHub
github.com › docker-library › postgres › issues › 756
with docker-compose.yml "Root or postgres or any role does not exist", postgres, postgrest, swagger connect to db · Issue #756 · docker-library/postgres
August 26, 2020 - version: '3.5' services: server: image: postgrest/postgrest ports: - "3000:3000" links: - db:db environment: PGRST_DB_URI: postgres://app_user:password@db:5432/app_db PGRST_DB_SCHEMA: public PGRST_DB_ANON_ROLE: app_user #In production this role should not be the same as the one used for the connection PGRST_SERVER_PROXY_URI: "http://127.0.0.1:3000" depends_on: - db container_name: server db: image: postgres ports: - "5432:5432" environment: POSTGRES_DB: app_db POSTGRES_USER: app_user POSTGRES_PASSWORD: password # Uncomment this if you want to persist the data.
Author   docker-library
Find elsewhere
🌐
Reddit
reddit.com › r/docker › postgresql in docker: database "admin" does not exist error
r/docker on Reddit: PostgreSQL in docker: database "admin" does not exist error
January 14, 2024 -

Hi,
I'm running the alpine PostgreSQL image in docker using the following docker-compose file below. After building and starting, the container gives the following fatal error message: "FATAL: database "admin" does not exist". After some googling it looks like postgresql needs a database to exist same to the user name that I declared in the docker-compose. Anyone an idea how to solve the error?

version: '3.8'

x-systeminfo: &systeminfo
  # Database
  POSTGRES_ADDRESS: database
  POSTGRES_DB: dev
  POSTGRES_USER: admin
  POSTGRES_PASSWORD: ****************
  POSTGRES_PORT: 5432

services:
  database:
build: ./Database
restart: always
ports:
   - 5432:5432
environment: *systeminfo
volumes:
   - postgresqldata:/var/lib/postgresql/data
healthcheck:
  test: pg_isready -U $$POSTGRES_USER
  interval: 10s
  timeout: 5s
  retries: 20

volumes:
  postgresqldata:

The docker file inside ./Database looks like this:

FROM postgres:alpine
COPY . /docker-entrypoint-initdb.d/
🌐
GitHub
github.com › docker-library › postgres › issues › 453
User and DB were not created from environment variable arguments · Issue #453 · docker-library/postgres
May 31, 2018 - docker run -it --rm --name postgres_db -v db-data:/var/lib/postgresql/data -p 5432:5432 -e POSTGRES_DB=snippet_db -e POSTGRES_USER=snippet_user -e POSTGRES_PASSWORD=P@88w0rd postgres_db ... 2018-05-31 21:57:03.245 UTC [147] FATAL: password authentication failed for user "snippet_user" 2018-05-31 21:57:03.245 UTC [147] DETAIL: Role "snippet_user" does not exist.
Author   docker-library
🌐
GitHub
github.com › LibrePhotos › librephotos-docker › issues › 59
FATAL: database "docker" does not exist · Issue #59 · LibrePhotos/librephotos-docker
July 7, 2022 - Following the instructions here exactly: https://docs.librephotos.com/1/standard_install/ yields the following endlessly repeating database error from the db container: FATAL: database "docker" does not exist · The files belonging to this database system will be owned by user "postgres".
Author   LibrePhotos
🌐
Docker Community
forums.docker.com › docker engine › compose
Docker does not create the database with the correct name - Compose - Docker Community Forums
November 15, 2022 - Hello everyone. I am defining 2 containers, 2 services, with docker composer. One is postgres and the other is pgadmin. The problem is that when I enter the postgrest server credentials in pgadmin, the maintenance database, which I define in the .yml file as “portal”, does not accept the connection and it does accept it if the maintenance database name is “postgres” as you can see in the following images and if I set in Maintenance database “portal”. it show up that portal database does no...
🌐
DEV Community
dev.to › frio_16 › fixing-fatal-database-does-not-exist-in-postgresql-docker-healthcheck-mistake-3il8
🐳 Fixing “FATAL: database does not exist” in PostgreSQL Docker (Healthcheck Mistake) - DEV Community
February 14, 2026 - services: postgres: image: postgres:16 container_name: train-postgres environment: POSTGRES_DB: train_db POSTGRES_USER: train_user POSTGRES_PASSWORD: train_pass ports: - "5433:5432" volumes: - train_pgdata:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U train_user"] interval: 5s timeout: 5s retries: 5 api: build: . container_name: train-api ports: - "8080:8080" depends_on: postgres: condition: service_healthy environment: ConnectionStrings__DefaultConnection: "Host=postgres;Port=5432;Database=train_db;Username=train_user;Password=train_pass" volumes: train_pgdata:
🌐
GitHub
github.com › htdvisser › taiga-docker › issues › 10
FATAL: database "/taigadocker_taigaback_1/postgres" does not exist · Issue #10 · htdvisser/taiga-docker
September 30, 2015 - db_1 | db_1 | LOG: database system was shut down at 2015-09-30 14:05:23 UTC db_1 | LOG: MultiXact member wraparound protections are now enabled db_1 | LOG: database system is ready to accept connections db_1 | LOG: autovacuum launcher started db_1 | LOG: incomplete startup packet db_1 | FATAL: database "/taigadocker_taigaback_1/postgres" does not exist taigaback_1 | Trying import local.py settings...
Author   htdvisser
🌐
GitHub
github.com › docker-library › postgres › issues › 285
DB, User not craeted using postgres docker-compose · Issue #285 · docker-library/postgres
May 16, 2017 - I was setting up my django project and postgres but everytime I was getting this error role doesn't exists or Db doesn't exists · So when I only tried to setup postgres and see if postgres is creating user and db correctly, but it wasn't ... version: "3" services: templates_db: image: postgres:9.6 ports: - "5432:5432" environment: - POSTGRES_USER=my_user - POSTGRES_PASSWORD=my_pass - POSTGRES_DB=my_db volumes: - ./data/postgres:/var/lib/postgresql/data · I ran my compose file using docker-compose up --build and got below logs · templates_db_1 | LOG: database system was interrupted; last kno
Author   docker-library
🌐
GitHub
github.com › pgracio › dhis2-docker › issues › 7
FATAL: database "${POSTGRES_DB}" does not exist · Issue #7 · pgracio/dhis2-docker
November 15, 2016 - Visiting localhost:8085 caused a long stream of FATAL: database "${POSTGRES_DB}" does not exist to repeat ad-infinitum.
Author   pgracio
Top answer
1 of 5
156

The problem was simple enough that my computer was already running an instance of Postgres that I was not aware was still running (not inside Docker) on :5432, checked with:

$ lsof -n -i:5432 | grep LISTEN

So I remembered I installed it via https://gist.github.com/sgnl/609557ebacd3378f3b72, I ran

$ pg-stop

And then I had no problem connecting to the Docker instance.

Edit (2019/07/02)

This question recently passed 10,000 views, so I thought I should elaborate more on why this happened.

Usually running through docker, using python and connecting to a postgres database requires you to install psycopg2, via pip3 install psycopg2, but if you run this command you will get:

Error: pg_config executable not found.

This is because psycopg2 requires an operating system install of the postgres libraries:

yum install postgresql-devel
apt-get install postgresql-client

Now, on a Mac, you will need to do the same with brew:

brew install postgresql

One thing that I didn't realise, is that on Mac, doing the above will not only install required libraries, but also start a database on :5432. Because this was all done in the background, it didn't occur to me that this was the problem as none of the usual errors popped up to inform that the port was being used, etc...

2 of 5
36

In my case, the problem may be due also to the use of a super user who is not postgres. Lhe developers chose the user georchestra in the geOrchestra docker composition. Extract from the dockerfile:

environment:
  - POSTGRES_USER=georchestra

HEALTHCHECK --interval=30s --timeout=30s \
  CMD pg_isready -U $POSTGRES_USER

consequently, you will have to use the option "-U georchestra" to connect to the container.

$ docker exec -it docker_database_1 psql -U georchestra
psql (10.5 (Debian 10.5-1.pgdg90+1))
Type "help" for help.

and of course, trying to connect with the user postgres causes an error:

docker exec -it docker_database_1 psql -U postgres
psql: FATAL:  role "postgres" does not exist
🌐
Medium
medium.com › @chunkang.wong94 › how-to-fix-the-role-postgres-does-not-exist-error-when-deploying-postgresql-docker-container-430e903b97fd
How to Fix the “Role ‘Postgres’ Does Not Exist” Error When Deploying PostgreSQL Docker Container | by ChunKang Wong | Medium
February 27, 2024 - How to Fix the “Role ‘Postgres’ Does Not Exist” Error When Deploying PostgreSQL Docker Container TL; DR: First check port usage on port 5432 using command sudo lsof -i :5432, there should be …
🌐
Docker Community
forums.docker.com › general
PostgreSQL container created with docker compose - databse already exists - General - Docker Community Forums
August 4, 2024 - Hi, One of my containers defined in docker-compose.yml file is PostgreSQL database. I am trying to initialize it with .sql script mounted on /docker-entrypoint-initdb.d/. Docker-compose works fine, but PostgreSQL logs s…