Dockerize application using docker-compose with PostgreSQL

This commit is contained in:
2026-01-24 13:31:47 +01:00
parent 01ae4a09ff
commit 52b5b301ef
4 changed files with 74 additions and 1 deletions

18
backend/Dockerfile Normal file
View File

@@ -0,0 +1,18 @@
FROM python:3.11-slim
WORKDIR /app
# Install system dependencies for psycopg2
RUN apt-get update && apt-get install -y \
libpq-dev \
gcc \
&& rm -rf /var/lib/apt/lists/*
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

38
docker-compose.yml Normal file
View File

@@ -0,0 +1,38 @@
version: '3.8'
services:
db:
image: postgres:15-alpine
container_name: ballet_db
environment:
POSTGRES_USER: ${POSTGRES_USER:-ballet_user}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-ballet_pass}
POSTGRES_DB: ${POSTGRES_DB:-ballet_prod}
volumes:
- postgres_data:/var/lib/postgresql/data
expose:
- 5432
backend:
build: ./backend
container_name: ballet_backend
environment:
DATABASE_URL: postgresql://${POSTGRES_USER:-ballet_user}:${POSTGRES_PASSWORD:-ballet_pass}@db:5432/${POSTGRES_DB:-ballet_prod}
SECRET_KEY: ${SECRET_KEY:-yoursecretkeyhere}
depends_on:
- db
ports:
- "8000:8000"
frontend:
build: ./frontend
container_name: ballet_frontend
environment:
API_URL: http://backend:8000
depends_on:
- backend
ports:
- "8080:8080"
volumes:
postgres_data:

17
frontend/Dockerfile Normal file
View File

@@ -0,0 +1,17 @@
FROM python:3.11-slim
WORKDIR /app
# NiceGUI might need some dependencies
RUN apt-get update && apt-get install -y \
procps \
&& rm -rf /var/lib/apt/lists/*
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8080
CMD ["python", "app.py"]

View File

@@ -138,4 +138,4 @@ def render_inventory_page():
]
ui.table(columns=columns, rows=rows, row_key='name')
ui.run(title="Suite de Producción de Ballet", port=8080)
ui.run(title="Suite de Producción de Ballet", port=8080, host='0.0.0.0')