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 OverflowYou 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
In my case, I've already had PostgreSQL working in the background on windows. And when I tried to connect to the docker container, I connected to my windows Postgres. You need to open services.msc and turn off PostreSQL
Docker does not create the database with the correct name
java - postgres database doesn't exist in docker container - Stack Overflow
database "postgres" does not exist
spring boot - Database does not exist - Docker/PostgreSQL - Stack Overflow
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/
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...
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