add dockerfile for backend

This commit is contained in:
2025-11-29 19:30:39 +01:00
parent 8282df0031
commit 4af9049937

52
backand/Dockerfile Normal file
View File

@@ -0,0 +1,52 @@
# ============================
# Stage 1: Build dependencies
# ============================
FROM python:3.13-slim AS builder
# Optimize Python
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# Install build tools (if needed for wheels)
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Create app working directory
WORKDIR /app
# Install Python dependencies
COPY requirements.txt .
RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt
# ============================
# Stage 2: Production image
# ============================
FROM python:3.13-slim
# Optimize Python
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# Create non-root user
RUN useradd -m -r appuser
# Create working directory
WORKDIR /app
# Copy installed dependencies from builder
COPY --from=builder /usr/local/lib/python3.13/site-packages/ /usr/local/lib/python3.13/site-packages/
COPY --from=builder /usr/local/bin/ /usr/local/bin/
# Copy application code with ownership
COPY --chown=appuser:appuser . .
# Switch to non-root user
USER appuser
# Expose Django port
EXPOSE 8000
# Run Django with uvicorn
CMD ["uvicorn", "MPM:application", "--host", "0.0.0.0", "--port", "7080"]