# FlaskPaste Slim Container Image (Distroless) # Build: podman build -f Containerfile.slim -t flaskpaste:slim . # Run: podman run -d -p 5000:5000 -v flaskpaste-data:/app/data flaskpaste:slim # # Distroless: No shell, no package manager, minimal attack surface # For debugging, use the standard Containerfile instead # Stage 1: Build dependencies (identical to standard build) FROM python:3.11-slim AS builder WORKDIR /build # Install build dependencies RUN apt update && apt install -y --no-install-recommends gcc \ && apt clean && rm -rf /var/lib/apt/lists/* # Create virtual environment and upgrade pip RUN python -m venv /opt/venv ENV PATH="/opt/venv/bin:$PATH" RUN pip install --no-cache-dir --upgrade pip wheel # Install Python dependencies COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt gunicorn \ && rm -rf /opt/venv/lib/python*/site-packages/setuptools/_vendor/jaraco.context*.dist-info # Stage 2: Distroless runtime FROM gcr.io/distroless/python3-debian12:nonroot LABEL maintainer="FlaskPaste" LABEL description="Minimal secure pastebin REST API (distroless)" WORKDIR /app # Copy virtual environment from builder # Note: distroless uses /usr/lib/python3.11 as base, venv provides all deps COPY --from=builder /opt/venv/lib/python3.11/site-packages /app/.local/lib/python3.11/site-packages # Copy application files (owned by nonroot user - uid 65532) COPY --chown=65532:65532 app/ ./app/ COPY --chown=65532:65532 wsgi.py . COPY --chown=65532:65532 fpaste . # Environment configuration ENV PYTHONPATH="/app/.local/lib/python3.11/site-packages" ENV FLASK_ENV=production ENV FLASKPASTE_DB=/app/data/pastes.db ENV PYTHONUNBUFFERED=1 ENV PYTHONDONTWRITEBYTECODE=1 EXPOSE 5000 # Healthcheck without shell (no || exit 1) HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \ CMD ["python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:5000/health')"] # Run gunicorn directly via Python module ENTRYPOINT ["python", "-m", "gunicorn"] CMD ["--bind", "0.0.0.0:5000", "--workers", "2", "--access-logfile", "-", "wsgi:application"]