Ich habe mit Django Version 5.1.6 entwickelt und es mehrere Monate lang in der Produktion verwendet. In der Produktion starte ich – wie auch in der Entwicklung – die Anwendung mit
Code: Select all
python manage.py runserver
Code: Select all
WARNING: This is a development server. Do not use it in a production setting. Use a production WSGI or ASGI server instead.
For more information on production servers see: https://docs.djangoproject.com/en/5.2/howto/deployment/
Code: Select all
# Stage 1: Base build stage
FROM python:3.13-slim AS builder
# Create the app directory
RUN mkdir /app
# Set the working directory
WORKDIR /app
# Set [url=viewtopic.php?t=25360]environment[/url] variables to optimize Python
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# Upgrade pip and install dependencies
RUN pip install --upgrade pip
# Copy the requirements file first (better caching)
COPY requirements.txt /app/
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Stage 2: Production stage
FROM python:3.13-slim
RUN useradd -m -r appuser && \
mkdir /app && \
chown -R appuser /app
# Copy the Python dependencies from the builder stage
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/
# Set the working directory
WORKDIR /app
# Copy application code
COPY --chown=appuser:appuser . .
# Set [url=viewtopic.php?t=25360]environment[/url] variables to optimize Python
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# Switch to non-root user
USER appuser
# Expose the application port
EXPOSE 8000
# Start the application using Gunicorn
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "3", "localmovies.wsgi:application"]
Code: Select all
[CRITICAL] WORKER TIMEOUT (pid:8)
Ich ändere dann die Docker-Datei, um den Entwicklungsserver zu starten und habe keine Probleme.
Ich habe auch uWSGI ausprobiert, war aber nicht erfolgreich. Ich sehe im Docker-Protokoll die Meldung
Code: Select all
[uWSGI] getting INI configuration from /uwsgi/uwsgi.ini
Jetzt meine Fragen:
Welche Lösung wird für die Verwendung einer Django-App in Docker empfohlen,
Entwicklungsserver
Gunicorn
uWSGI
...
Hat jemand eine Idee, warum Gunicorn das hat? Timeouts und der Entwicklungsserver nicht?
Kann jemand eine Anleitung für uWSGI mit Django und Docker vorschlagen?
Mobile version