Using uv Docker Images
1
Select a base image
Use one of the official uv Docker images. You can choose from distroless, Alpine, or Debian-based images:
2
For distroless images
When using distroless images, specify the entrypoint:
Pipeline Configuration
Here’s a complete example pipeline:Caching Dependencies
Persist the uv cache between pipeline runs to improve performance:Use
uv cache prune --ci to reduce cache size. See the cache documentation for more details.Advanced Caching
Cache based on both lockfile and Python version:Matrix Testing
Test across multiple Python versions:Using uv pip
For workflows using theuv pip interface, enable system Python:
When using
uv pip, consider using requirements.txt or pyproject.toml instead of uv.lock in your cache key.Installing uv in Custom Images
If you need to use a custom base image:Complete Example with Multiple Stages
Best Practices
- Pin versions: Always specify exact versions for
UV_VERSIONandPYTHON_VERSION - Use cache: Enable caching to speed up pipeline runs
- Set UV_LINK_MODE: Use
copymode since GitLab creates separate mountpoints - Prune cache: Run
uv cache prune --ciinafter_scriptto optimize cache size - Cache key: Use
uv.lockas the cache key for projects,requirements.txtfor pip workflows