https://github.com/benitomartin/uv-docker-benchmark
Docker Container Optimization Benchmark
https://github.com/benitomartin/uv-docker-benchmark
benchmark docker fastapi python uv
Last synced: about 2 months ago
JSON representation
Docker Container Optimization Benchmark
- Host: GitHub
- URL: https://github.com/benitomartin/uv-docker-benchmark
- Owner: benitomartin
- License: mit
- Created: 2025-03-18T10:47:11.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-15T08:28:17.000Z (about 1 year ago)
- Last Synced: 2025-06-25T07:46:04.130Z (12 months ago)
- Topics: benchmark, docker, fastapi, python, uv
- Language: Python
- Homepage: https://medium.com/@benitomartin/deep-dive-into-uv-dockerfiles-by-astral-image-size-performance-best-practices-5790974b9579
- Size: 191 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Docker + uv Benchmark

This project demonstrates different approaches to building Python applications using `uv` package manager with Docker, featuring three distinct Dockerfile strategies:
- `singlestage.Dockerfile`: Single-stage build that keeps `uv` in the final image
- `standalone.Dockerfile`: Multi-stage build using system Python, removes `uv` in the final stage
- `multistage.Dockerfile`: Multi-stage build using uv-managed Python, removes `uv` in the final stage
The following [blog](https://medium.com/@benitomartin/deep-dive-into-uv-dockerfiles-by-astral-image-size-performance-best-practices-5790974b9579) describes the differences between these strategies.
## Project Structure
```
.
├── singlestage.Dockerfile
├── multistage.Dockerfile
├── standalone.Dockerfile
├── src/
│ └── uv_docker_example/
│ └── __init__.py
├── pyproject.toml
├── uv.lock
├── .dockerignore
└── benchmark_docker_images.py
```
## Benchmarking
The project includes a comprehensive benchmarking tool (`benchmark_docker_images.py`) that measures:
- Image sizes
- Build times
To run the benchmark:
```bash
uv venv
source .venv/bin/activate
uv sync
uv run benchmark_docker_images.py
```
The script will:
1. Build each Dockerfile
2. Compare results between different strategies
3. Clean up images after testing
### Sample Benchmark Output
Size (including all dependencies):
- Multi-Stage → 4'126.72 MB
- Standalone → 4'157.44 MB
- Single-Stage → 4'188.16 MB
Build time:
- Multi-Stage → 2m 9.5s
- Standalone → 2m 16.6s
- Single-Stage → 3m 0.5s
## Dependencies
Main dependencies:
- FastAPI
- scikit-learn
- MLflow
- TensorFlow
- LightGBM
- NumPy
- Pandas
- PyArrow
- SciPy
- Pydantic
Development dependencies:
- Ruff (≥0.6.2)
- FastAPI CLI (≥0.0.5)
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.