Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Servers, nginx and Docker

uv sync --locked fails inside docker build but passes on your machine

Your error

error: The lockfile at `uv.lock` needs to be updated, but `--locked` was provided. To update the lockfile, run `uv lock`.1 more line it can show

Fix it fast

Most common cause, 1 of 2

Workspace member pyproject.toml files are not in the image yet

Use --frozen in the dependency-only layer, which installs from uv.lock without checking it, and keep --locked for the final sync once all members are copied.

Fix
RUN --mount=type=cache,target=/root/.cache/uv \
    --mount=type=bind,source=uv.lock,target=uv.lock \
    uv sync --frozen --no-install-workspace
COPY . /app
RUN --mount=type=cache,target=/root/.cache/uv \
    uv sync --locked
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

Inside docker build, the uv message that uv.lock needs to be updated but --locked was provided usually means uv cannot see the same project metadata as your machine. Workspace members' pyproject.toml files are missing at that step, or the image's uv differs from yours. Use --frozen for the dependency layer, --locked after COPY, and pin uv. Applies to uv 0.13.

  • Applies to uv 0.13.9, Docker BuildKit, ghcr.io/astral-sh/uv:0.13.9
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Compare the uv tag in the Dockerfile with your local uv version, then check whether the project is a workspace. A :latest tag or a different version number points to cause 2. A workspace whose member folders are not yet copied when the failing RUN line executes is cause 1.

Run this first
uv --version
grep -n "astral-sh/uv" Dockerfile
grep -n -A4 "tool.uv.workspace" pyproject.toml

Then find the line you see in this list and open its fix:

  1. 1Workspace member pyproject.toml files are not in the image yetpyproject.toml has a [tool.uv.workspace] members list, and the failing RUN comes before COPY . /app or mounts only uv.lock and the root pyproject.toml
  2. 2The image runs a different uv release than the one that wrote uv.lockThe Dockerfile copies uv from the :latest tag, or from a version tag other than the one uv --version prints on your machine

What does the error look like?

  • error: The lockfile at `uv.lock` needs to be updated, but `--locked` was provided. To update the lockfile, run `uv lock`.
  • The lockfile at `uv.lock` needs to be updated, but `--locked` was provided

Cause 1 of 2

Workspace member pyproject.toml files are not in the image yet

You seepyproject.toml has a [tool.uv.workspace] members list, and the failing RUN comes before COPY . /app or mounts only uv.lock and the root pyproject.toml

Check

uv sync --locked compares uv.lock with the project metadata, and in a workspace that metadata includes every member's pyproject.toml. The uv Docker guide says uv cannot assert the lockfile is up-to-date without those files, so an early layer that has only the root files fails the check. A .dockerignore rule that excludes a member folder does the same.

Check
grep -n -E "COPY|uv sync|mount=type=bind" Dockerfile

Fix

Use --frozen in the dependency-only layer, which installs from uv.lock without checking it, and keep --locked for the final sync once all members are copied. Add --no-install-workspace so the early layer skips your own packages.

Fix
RUN --mount=type=cache,target=/root/.cache/uv \
    --mount=type=bind,source=uv.lock,target=uv.lock \
    uv sync --frozen --no-install-workspace
COPY . /app
RUN --mount=type=cache,target=/root/.cache/uv \
    uv sync --locked

Verify

docker build completes both sync steps, and the final --locked sync passes because every member is present.

Verify
docker build --no-cache -t myapp .

Confirmed by docs.astral.sh

Did this fix it?

Cause 2 of 2

The image runs a different uv release than the one that wrote uv.lock

You seeThe Dockerfile copies uv from the :latest tag, or from a version tag other than the one uv --version prints on your machine

Check

When the Docker uv differs from your local uv, the lock check can fail even though uv.lock is unchanged. uv only guarantees lockfile compatibility within one minor release, and a real case exists: in projects with an explicit index URL, lockfiles from 0.7.15 and earlier failed --locked with this exact message under 0.7.16, until maintainers merged a fix.

Check
grep -n "astral-sh/uv" Dockerfile

Fix

Copy uv from a version tag that matches your local version, and record the range in pyproject.toml with required-version so a mismatched uv stops with a clear error instead.

Fix
# Dockerfile
COPY --from=ghcr.io/astral-sh/uv:0.13.9 /uv /uvx /bin/

# pyproject.toml
[tool.uv]
required-version = "==0.13.9"

Verify

uv --version in the image matches your machine, and uv lock --check passes both locally and in the build.

Verify
uv lock --check && docker build -t myapp .

Confirmed by docs.astral.sh

Did this fix it?

How do I stop it coming back?

  • Pin the uv image tag in every Dockerfile and bump it in the same commit as the local uv upgrade.
  • Run uv lock --check in CI before docker build, so a stale uv.lock fails early with a clear log.
  • List workspace member folders in a comment above the COPY lines, and review .dockerignore whenever a member is added.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: TaxiDex, Dispatch Pro.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.