๐ณ Dockerfiles
A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image.
Mastering this concept will significantly boost your Python data science skills!
๐ป Code Example:
# โโ Dockerfile for Pynfinity Flask App โโโโโโโโโโโโโโโโโโโโโโโ # Multi-stage build โ slim production image # Stage 1: Build dependencies FROM python:3.12-slim AS builder WORKDIR /build COPY requirements.txt . RUN pip install --upgrade pip \ && pip wheel --no-cache-dir --no-deps --wheel-dir /wheels -r requirements.txt # Stage 2: Production image FROM python:3.12-slim AS production ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ FLASK_ENV=production WORKDIR /app # Copy pre-built wheels from builder COPY --from=builder /wheels /wheels COPY --from=builder /build/requirements.txt . RUN pip install --no-cache /wheels/* # Copy application source COPY . . # Non-root user for security RUN addgroup --system pynfinity && adduser --system --group pynfinity USER pynfinity EXPOSE 8000 HEALTHCHECK --interval=30s --timeout=10s --retries=3 \ CMD curl -f http://localhost:8000/api/site-stats || exit 1 CMD ["gunicorn", "--workers=4", "--bind=0.0.0.0:8000", "runserver:app"]
Keep exploring and happy coding! ๐ป