I trying to create a Postgres Database with Docker Compose, but i'm not understanding why the PSQL client is telling me that a database called root doesn't exists.
That's the docker-compose.yml
version: '3.3'
services:
postgres:
container_name: postgres
image: "library/postgres:latest"
env_file:
- .env # configure postgres
volumes:
- database-data:/var/lib/postgresql/data/ # persist data even if container shuts down
environment:
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_USER: ${DB_USER}
POSTGRES_DB: ${DB_DATABASE}
ports:
- "5432:5432"
restart: unless-stopped
volumes:
database-data:
When i run docker-compose exec postgres env
it gives the right variables
POSTGRES_PASSWORD=4544
POSTGRES_USER=root
POSTGRES_DB=xpack
And when i run docker exec -it postgres /bin/bash
and psql
it returns the following error:
root@0719bff80472:/# psql -U root
psql: error: could not connect to server: FATAL: database "root" does not exist
I don't if my database was created or not