Skip to main content
uv provides official Docker images and integrates seamlessly with Docker workflows for Python dependency management. This guide covers best practices for using uv in Docker to optimize build times and image sizes.

Available Images

uv provides both distroless images (containing only uv binaries) and derived images (based on popular base images with uv pre-installed).

Distroless Images

Derived Images

Installing uv

1

Copy from distroless image

The recommended approach is to copy the uv binary from the official distroless image:
For reproducible builds, pin to a specific SHA256:
2

Alternative: Use installer

You can also use the installer script:

Basic Project Setup

1

Install uv and copy project

Add .venv to your .dockerignore file to prevent including the local virtual environment in the image.
2

Sync dependencies

3

Set up the entrypoint

Multi-Stage Build with Intermediate Layers

Optimize build times by separating dependency installation from project installation:

For Workspaces

When using workspaces, use --frozen and --no-install-workspace:

Production Optimization

Non-Editable Multi-Stage Build

Create smaller production images by excluding source code:

Compile Bytecode

Improve startup time by compiling Python bytecode:

Caching

Use cache mounts to speed up builds:
For managed Python installations:

Development Setup

Using docker run

Mount your project while preserving the container’s virtual environment:

Using Docker Compose with Watch

Run with:

Using uv pip

1

Enable system Python

2

Install packages

3

Install from requirements

Installing Tools

Make installed tools available in the PATH:

Verifying Image Provenance

Verify official uv images using GitHub attestations:

Complete Example

See the uv-docker-example repository for a complete working example demonstrating best practices.