A Python API that works on one laptop can still be painful to deploy if the image is bloated, runs as root, or rebuilds dependencies on every copy change. A clear multi-stage Dockerfile, plus a slightly different compose setup for local work, gives you the same service in development and in production without copying build tools into the runtime image.
This guide is a practical pattern for FastAPI and other Python APIs. It is not a full Kubernetes guide. The aim is a small, non-root image, fast rebuilds, and a local workflow that does not pretend to be production.
A production multi-stage Dockerfile
The builder stage installs compilers and Poetry, then creates a virtualenv.…