BirthdayM / Dockerfile
ayush2917's picture
Update Dockerfile
a172bd0 verified
raw
history blame
1.46 kB
# Use Python 3.9 slim-buster for stability and smaller footprint
FROM python:3.9-slim-buster AS builder
# Install system dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
gcc \
python3-dev \
libssl-dev \
curl \
&& rm -rf /var/lib/apt/lists/*
# Create and activate virtual environment
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# ========== Runtime Stage ========== #
FROM python:3.9-slim-buster
# Install runtime dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
libssl1.1 \
curl \
&& rm -rf /var/lib/apt/lists/*
# Copy virtual environment from builder
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Create non-root user
RUN useradd -m -u 1001 krishna
USER krishna
WORKDIR /home/krishna/app
# Copy application code (with proper ownership)
COPY --chown=krishna:krishna . .
# Environment variables
ENV PORT=7860 \
PYTHONUNBUFFERED=1 \
PYTHONPATH=/home/krishna/app \
GUNICORN_CMD_ARGS="--bind=0.0.0.0:7860 --workers=1 --threads=2 --timeout=120 --worker-class=gthread --log-level=info"
# Expose port and health check
EXPOSE 7860
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD curl -f http://localhost:7860/ || exit 1
# Run Gunicorn
CMD ["gunicorn", "app:app"]