Dockerfile 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. FROM python:3.10-slim
  2. WORKDIR /app
  3. ENV PYTHONDONTWRITEBYTECODE 1
  4. ENV PYTHONUNBUFFERED 1
  5. # Global setting to suppress "Running as root" warning for all pip commands
  6. ENV PIP_ROOT_USER_ACTION=ignore
  7. # Prevent debconf errors during build
  8. ARG DEBIAN_FRONTEND=noninteractive
  9. # Update apt source to TUNA (Optional, speeds up system package install) and install dependencies
  10. RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list.d/debian.sources || true \
  11. && apt-get update && apt-get install -y --no-install-recommends \
  12. gcc \
  13. default-libmysqlclient-dev \
  14. pkg-config \
  15. tzdata \
  16. && rm -rf /var/lib/apt/lists/*
  17. COPY requirements.txt .
  18. # Use Tsinghua PyPI Mirror & Upgrade pip
  19. RUN pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple \
  20. && pip install --no-cache-dir -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
  21. COPY . .
  22. # Run application with Gunicorn + Uvicorn Workers (multi-process)
  23. # This enables cross-process WebSocket message broadcasting via Redis Pub/Sub
  24. CMD ["gunicorn", "app.main:app", "-k", "uvicorn.workers.UvicornWorker", "--workers", "4", "--bind", "0.0.0.0:8000", "--timeout", "120", "--keep-alive", "5"]