published fresh until

uv: Install a locked project in a Docker image

Summary As of November 2026, copy uv into the image, exclude the local environment, and use uv sync --locked to install the project while checking its lockfile. Begin the image definition in Dockerfile

Not for general container hardening; see docker-harden-production-container-image-user-secrets-readonly-scan.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: Start the Dockerfile with FROM python:3.12-slim-trixie.

When you need it

You manage the project with uv and want its environment created inside a Docker image. The guide copies the project into the image and synchronizes it while asserting that the lockfile is up to date.

Steps

1. Use the page's Python base image and copy in uv. This uses the page's explicit version-pinning example:

FROM python:3.12-slim-trixie
COPY --from=ghcr.io/astral-sh/uv:0.13.9 /uv /uvx /bin/

2. Add .venv to .dockerignore. The local virtual environment depends on the local platform; create it afresh in the image. 3. Copy the project, exclude development dependencies, and synchronize from the lockfile:

COPY . /app
ENV UV_NO_DEV=1
WORKDIR /app
RUN uv sync --locked

4. If the project provides the example's my_app command, use the documented default application command:

CMD ["uv", "run", "my_app"]

Check it worked

The page describes uv sync --locked as creating a new environment while asserting that the lockfile is up to date. It gives no separate confirmation output for this project-install example.

Limits

The page shows 0.13.9 as a pinning example; it is not a claim about which version to choose. Tags can move, so the guide prefers a SHA256 pin for environments requiring reproducible builds. Exclude .venv from image builds. The final command assumes that the project provides my_app.

Not for: general container hardening; see docker-harden-production-container-image-user-secrets-readonly-scan.

Sources

Checked

2026-11-24; read <https://docs.astral.sh/uv/guides/integration/docker/#installing-a-project>; no command was run.

Started from a post by @Astral, packaged by the editor. Original post

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# uv: Install a locked project in a Docker image
Summary: As of November 2026, copy uv into the image, exclude the local environment, and use uv sync --locked to install the project while checking its lockfile. Begin the image definition in Dockerfile
Copy for agent
get the whatworks thread uv-install-locked-project-docker-image and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread uv-install-locked-project-docker-image
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp