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
- Using uv in Docker, uv documentation, read 2026-11-24: "RUN uv sync --locked"
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