1# Production-ready Dockerfile for Flask application
2# Used by docker-compose.yml
3
4FROM python:3.11-slim
5
6LABEL maintainer="your-email@example.com"
7LABEL description="Flask app with PostgreSQL and Redis"
8
9# Install system dependencies
10RUN apt-get update && apt-get install -y --no-install-recommends \
11 libpq-dev \
12 gcc \
13 && rm -rf /var/lib/apt/lists/*
14
15# Create non-root user
16RUN useradd -m -u 1000 appuser && \
17 mkdir -p /app && \
18 chown -R appuser:appuser /app
19
20WORKDIR /app
21
22# Copy and install dependencies
23COPY --chown=appuser:appuser requirements.txt .
24RUN pip install --no-cache-dir -r requirements.txt
25
26# Copy application code
27COPY --chown=appuser:appuser app.py .
28
29USER appuser
30
31EXPOSE 5000
32
33HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
34 CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:5000/health')" || exit 1
35
36CMD ["python", "app.py"]