This example demonstrates building a FastAPI web service using the Python Container Builder.
- ✅ Web service with external dependencies
- ✅ Using
uvfor fast dependency installation - ✅ Multi-stage build to distroless runtime
- ✅ Health check endpoint
fastapi/
├── Dockerfile
├── requirements.txt
└── main.py
docker build -t fastapi-example .docker run -p 8000:8000 fastapi-exampleThen visit http://localhost:8000/docs to see the interactive API documentation.
# Health check
curl http://localhost:8000/health
# Get current time
curl http://localhost:8000/time
# Echo endpoint
curl -X POST http://localhost:8000/echo \
-H "Content-Type: application/json" \
-d '{"message": "Hello, World!"}'FROM ghcr.io/jski/python-container-builder:3.12 as build-venv
COPY requirements.txt /requirements.txt
RUN uv pip install -r /requirements.txtFROM gcr.io/distroless/python3-debian12
COPY --from=build-venv /.venv /.venv
COPY main.py /app/main.py
WORKDIR /app
ENTRYPOINT ["/.venv/bin/python3", "-u", "main.py"]- Fast builds -
uvinstalls dependencies much faster than pip - Small images - Distroless runtime contains only what's needed
- Security - No package manager or shell in final image
- Reliable - Virtual environment ensures dependency isolation
Change the build image tag:
FROM ghcr.io/jski/python-container-builder:3.11 as build-venv
# Also change the runtime to match:
FROM gcr.io/distroless/python3-debian12Just update requirements.txt and rebuild. The build cache will reuse unchanged layers.
Consider adding:
- Environment variable for host/port configuration
- Multiple workers (uvicorn --workers)
- Health check monitoring
- Logging configuration