DevOps / Scripts
dockerfile
Advanced
Python Multi-stage Dockerfile
Minimal production Python image using multi-stage build — under 120 MB final size.
dockerfile
FROM python:3.12-slim AS builder
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
FROM python:3.12-slim
WORKDIR /app
COPY --from=builder /install /usr/local
COPY . .
EXPOSE 8000
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
Prerequisites
- Docker >= 20
- Python project with requirements.txt
Pro Tips
- → Add USER appuser to run as non-root.
Commercial Licensing
Acquire a production access token or template license for enterprise deployment.
Module Info
- Language
- dockerfile
- Level
- Advanced
- Read time
- 3 min
- Published
- Jul 2025
- License
- Commercial License
Newsletter
New modules every week, directly to your inbox.
Similar Modules
Postgres S3 Backup
Dump a Postgres database, gzip it, push to S3 with AES256 encryption.
bash
·
Intermediate
Disk Usage Alert
Send an alert when any mounted filesystem exceeds a usage threshold.
bash
·
Beginner
Docker Image Cleanup Script
Remove dangling images, stopped containers and unused volumes in one pass.
bash
·
Intermediate