Shell form CMD makes /bin/sh PID 1 — SIGTERM from docker stop goes to the shell, not uvicorn, causing SIGKILL after the stop timeout instead of graceful shutdown. Using CMD ["sh", "-c", "exec uvicorn ..."] lets the shell expand $WEB_WORKERS then exec-replaces itself with uvicorn, restoring correct signal delivery. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
34 lines
937 B
Docker
34 lines
937 B
Docker
# Use official Python slim image
|
|
FROM python:3.12-slim
|
|
|
|
# Set Python optimizations
|
|
ENV PYTHONUNBUFFERED=1
|
|
ENV PYTHONDONTWRITEBYTECODE=1
|
|
ENV PIP_NO_CACHE_DIR=1
|
|
|
|
WORKDIR /usr/src/app
|
|
|
|
# Install system dependencies (PostgreSQL client libraries)
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
libpq-dev \
|
|
curl \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Copy and install Python dependencies
|
|
COPY requirements.txt ./
|
|
RUN pip install --no-cache-dir --upgrade pip && \
|
|
pip install --no-cache-dir -r requirements.txt
|
|
|
|
# Copy application code
|
|
COPY ./app /usr/src/app/app
|
|
|
|
# Create directories for volumes
|
|
RUN mkdir -p /usr/src/app/storage
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
|
|
CMD curl -f http://localhost:80/api/v3/current || exit 1
|
|
|
|
# Start uvicorn
|
|
ENV WEB_WORKERS=2
|
|
CMD ["sh", "-c", "exec uvicorn app.main:app --host 0.0.0.0 --port 80 --workers $WEB_WORKERS"] |