Code: Select all
.
├── docker-compose.yml
├── Dockerfile
└── app
| ├── __init__.py
| ├── database
| | ├── alembic/
| | ├── __init__.py
| | ├── db.py
| | └── models.py
| ├── other
| ├── source
| └── files
├── other
└── files
Code: Select all
postgresql://{username}:{password}@db:5432/{database}Code: Select all
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not translate host name "db" to address: Name or service not known
Dieser Workflow scheint nicht richtig zu sein. Wie arbeiten Menschen mit Datenbanken in Projekten, die Container verwenden?
Die Datei docker-compose.yml sieht folgendermaßen aus:
Code: Select all
version: "3"
services:
db:
image: postgres
ports:
- "5432:5432"
environment:
- POSTGRES_USER=username
- POSTGRES_PASSWORD=password
- POSTGRES_DB=database
app:
build: .
command: bash -c "cd app/database && alembic upgrade head && cd ../.. && python app/main.py"
volumes:
- .:/code
ports:
- "5000:5000"
depends_on:
- db
Mobile version