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
🌐
GitHub
github.com › docker-library › postgres › issues › 403
FATAL: database does not exist [docker compose] · Issue #403 · docker-library/postgres
January 26, 2018 - version: '2' services: postgres: image: "library/postgres:latest" environment: - POSTGRES_USER=test - POSTGRES_PASSWORD=qwerty - POSTGRES_DB=mydb ... docker run -it -e POSTGRES_USER=test -e POSTGRES_PASSWORD=qwerty -e POSTGRES_DATABSE=mydb postgres docker exec -it <CONTAINER_ID> /bin/bash psql -U test
Author   docker-library
Discussions

Docker does not create the database with the correct name
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 ... More on forums.docker.com
🌐 forums.docker.com
1
0
November 15, 2022
java - postgres database doesn't exist in docker container - Stack Overflow
When I built my app image everything was ok, then I should start my db image and app image. I start db with docker-compose up db and I got: org.postgresql.util.PSQLException: FATAL: database "haircut_studio" does not exist. Is something wrong with my DbConfig? More on stackoverflow.com
🌐 stackoverflow.com
database "postgres" does not exist
I have searched for existing issues search for existing issues, including closed ones. I confirm that I am using English to submit this report (我已阅读并同意 Language Policy). [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) · Please do not modify this template :) and fill in all the required fields. ... docker-db-1 | docker-db-1 | PostgreSQL Database ... More on github.com
🌐 github.com
2
September 9, 2024
spring boot - Database does not exist - Docker/PostgreSQL - Stack Overflow
So I been working around with Springboot and am trying to setup a PostgreSQL database in a docker container. I have the following bash script to create the container: #!/usr/bin/env bash set -euo More on stackoverflow.com
🌐 stackoverflow.com
🌐
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/
🌐
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...
🌐
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:54.594 UTC [1] LOG: starting PostgreSQL 15.8 on aarch64-unknown-linux-musl, compiled by gcc (Alpine 13.2.1_git20240309) 13.2.1 20240309, 64-bit docker-db-1 | 2024-09-09 08:39:54.595 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432 docker-db-1 | 2024-09-09 08:39:54.595 UTC [1] LOG: listening on IPv6 address "::", port 5432 docker-db-1 | 2024-09-09 08:39:54.606 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" docker-db-1 | 2024-09-09 08:39:54.721 UTC [37] LOG: database system was shut down at 2024-09-09 08:29:08 UTC docker-db-1 | 2024-09-09 08:39:54.794 UTC [1] LOG: database system is ready to accept connections docker-web-1 | pm2 launched in no-daemon mode (you can add DEBUG="*" env variable to get more messages)
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
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 71059557 › docker-fatal-database-does-not-exist
postgresql - Docker - "FATAL: database does not exist" - Stack Overflow
February 10, 2022 - You're not using an image built from the repository to which you just linked. The official postgres image doesn't support POSTGRES_MULTIPLE_DATABASES so it's not creating any of your databases.
🌐
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:
🌐
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…
🌐
Stack Overflow
stackoverflow.com › questions › 79565657 › the-postgresql-container-is-running-fine-with-no-errors-but-the-app-still-throw
java - The PostgreSQL container is running fine with no errors, but the app still throws a “database does not exist” error - Stack Overflow
can you check if the database name is matching with springboot db name. docker exec -it postgres psql -U postgres -c '\l' ... Save this answer. ... Show activity on this post. I think the DB is connected properly, and the error seems to be caused ...
🌐
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 the image create a 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
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
🌐
Connect
connect.hyland.com › t5 › alfresco-forum › fatal-database-quot-alfresco-quot-does-not-exist › td-p › 139738
FATAL: database "alfresco" does not exist - Hyland Connect - 139738
March 22, 2022 - I attached an image of the error in question, there are times when instead of saying "FATAL: database "alfresco" does not exist" it says "FATAL: database "activiti" does not exist". I emphasize that I am doing the "run.bat build_start" of the main repository of the project in which other people are working and everything works correctly, but neither those people nor the team leader know why this happens to me. Just in case, the Postgres part of the "docker-compose.yml" file is as follows:
Top answer
1 of 1
1

Are you sure your database init script is getting called? The postgresql docker uses files in /docker-entrypoint-initdb.d/* as you can see in the Dockerfile here: https://github.com/docker-library/postgres/blob/443c7947d548b1c607e06f7a75ca475de7ff3284/9.4/docker-entrypoint.sh#L77

You can test this by bringing up ONLY the database, by running something like

docker-compose up db

which will ONLY bring up the db container, and then you can docker exec -it in and psql into the postgres processes, or use your exposed port on 5432

Also, you may want to pass in the initialization of the database, username, and password the way the Dockerfile expects them, as env variables as you can see in the same file

Environment Variables The PostgreSQL image uses several environment variables which are easy to miss. While none of the variables are required, they may significantly aid you in using the image.

POSTGRES_PASSWORD This environment variable is recommended for you to use the PostgreSQL image. This environment variable sets the superuser password for PostgreSQL. The default superuser is defined by the POSTGRES_USER environment variable. In the above example, it is being set to "mysecretpassword".

POSTGRES_USER This optional environment variable is used in conjunction with POSTGRES_PASSWORD to set a user and its password. This variable will create the specified user with superuser power and a database with the same name. If it is not specified, then the default user of postgres will be used.

POSTGRES_DB This optional environment variable can be used to define a different name for the default database that is created when the image is first started. If it is not specified, then the value of POSTGRES_USER will be used.

https://hub.docker.com/_/postgres/