Postgres: FATAL: database does not exist [docker compose]

Created on 26 Jan 2018  路  2Comments  路  Source: docker-library/postgres

We have docker compose.yml

version: '2'
services:
 postgres:
 image: "library/postgres:latest"
 environment:
 - POSTGRES_USER=test
 - POSTGRES_PASSWORD=qwerty
 - POSTGRES_DB=mydb

execute:

docker-compose up
docker exec -it <CONTAINER_ID> /bin/bash
psql -U test

and we get this error:

psql: FATAL: database "test" does not exist

Everything works fine witout compose

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

results:

root@cb18469bc86e:/# psql -U test
psql (10.1)
Type "help" for help.

test=# 

Most helpful comment

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.

POSTGRES_DATABSE (from your docker run line) is not used.

All 2 comments

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.

POSTGRES_DATABSE (from your docker run line) is not used.

thanks a lot! my bad :)

Was this page helpful?
0 / 5 - 0 ratings