FlashCardBackEnd / Dockerfile
JeorgeC's picture
Update Dockerfile
1c5882a verified
# Use Python 3.10 slim image for better performance
FROM python:3.10-slim
# Set working directory
WORKDIR /app
# Install system dependencies for better stability
RUN apt-get update && apt-get install -y \
gcc \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements first for better Docker layer caching
COPY requirements.txt .
# Install Python dependencies with no cache to reduce image size
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY . .
# Create a non-root user for security
RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
USER appuser
# Expose port 7860 (Hugging Face Spaces default)
EXPOSE 7860
# Add health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:7860/health || exit 1
# Set environment variables for better Python behavior
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
# Run the application with proper signal handling
CMD ["python", "-u", "app.py"]