I have the following docker-compose file and when I ran docker-compose up -d --build
, I got a message which indicated success. The logs did not have any exception printed.
[+] Running 2/2
✔ Container fastapi-tdd-docker-web-db-1 Running 0.0s
✔ Container fastapi-tdd-docker-web-1 Started
But when I try to access the postgres DB with docker-compose exec web-db psql -U postgres
, then try c web_dev
, I get this error
connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: database "web_dev" does not exist
Previous connection kept
here is my docker compose yaml file – what is going wrong here?
version: '3.8'
services:
web:
build: ./project
command: uvicorn app.main:app --reload --workers 1 --host 0.0.0.0 --port 8000
volumes:
- ./project:/usr/src/app
ports:
- 8004:8000
environment:
- ENVIRONMENT=dev
- TESTING=0
- DATABASE_URL=postgres://postgres:postgres@web-db:5432/web_dev
- DATABASE_TEST_URL=postgres://postgres:postgres@web-db:5432/web_test
depends_on:
- web-db
web-db:
build:
context: ./project/db
dockerfile: Dockerfile
expose:
- 5432
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres