build-python-dockerfiles
Installation
SKILL.md
Build Python Dockerfiles
Use this skill to author Dockerfiles for Python projects using uv and multi-stage builds.
The default pattern is based on Hynek Schlawack's article Production-ready Python Docker Containers with uv.
Workflow
- Detect whether the project is packaged (installable) or unpackaged (run from copied source).
- Choose a base image strategy:
- Default to
python:<version>-slimfor generic Python services. - Use an OS image like
ubuntu:noblewhen system packages or org-standard base images matter. - Keep build and runtime on the same distro family.
- Avoid Alpine unless the user has a hard requirement.
- Default to
- Install dependencies before copying source so lockfile changes and app code changes stay in separate layers.
- Keep dependency sync and app install in separate
uv syncsteps. - Pick the runtime command pattern that matches the app type.
- Verify the final Dockerfile against the checklist in this file.