Qodo / Dockerfile
rkihacker's picture
Create Dockerfile
bc46406 verified
# Use Python 3.11 slim image for smaller size and security
FROM python:3.11-slim
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONPATH=/app \
PORT=8000
# Create a non-root user for security
RUN groupadd --gid 1000 appuser && \
useradd --uid 1000 --gid appuser --shell /bin/bash --create-home appuser
# Set working directory
WORKDIR /app
# Install system dependencies required for curl-cffi and other packages
RUN apt-get update && apt-get install -y \
--no-install-recommends \
build-essential \
curl \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Copy requirements first for better Docker layer caching
COPY requirements.txt .
# Install Python dependencies
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY main.py .
# Change ownership of the app directory to the non-root user
RUN chown -R appuser:appuser /app
# Switch to non-root user
USER appuser
# Expose the port the app runs on
EXPOSE 8000
# Add health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
# Command to run the application
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "1"]