expenses_manager/Dockerfile
jkuijperm 5f5b30108e Build: imagen autocontenida, .dockerignore y limpieza de requirements
- Dockerfile copia el proyecto Django, no la raiz del repo, para que
  manage.py y wsgi.py queden donde gunicorn los espera
- collectstatic en tiempo de construccion y CMD en la imagen
- .dockerignore: evita que .env, .git y artefactos locales entren en la imagen
- requirements.txt sin BOM
2026-09-29 17:32:21 +02:00

31 lines
1.2 KiB
Docker

FROM python:3.11-slim
# Fail fast and log straight to stdout, so `docker-compose logs` is useful.
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
WORKDIR /app
# Dependencies first: this layer is cached and only rebuilt when
# requirements.txt changes, not on every code change.
COPY expenses_manager/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy the Django project itself, not the repository root, so that /app is
# the directory holding manage.py. The previous version copied the repo root
# into /app/expenses_manager, which left manage.py and wsgi.py one level
# deeper than the gunicorn command expected.
COPY expenses_manager/ .
# Collect static files at build time so the running container never needs to
# write to its own filesystem. SECRET_KEY is required by settings.py when
# DEBUG is False, but collectstatic never uses it, so a throwaway value is
# enough — the real one comes from the environment at runtime.
RUN SECRET_KEY=build-time-placeholder \
DEBUG=False \
ALLOWED_HOSTS=localhost \
python manage.py collectstatic --noinput
EXPOSE 8000
CMD ["gunicorn", "expenses_manager.wsgi:application", "--bind", "0.0.0.0:8000"]