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 showFix it fast
Most common cause, 1 of 2Workspace 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.
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 --lockedShort 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.
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.
uv --version
grep -n "astral-sh/uv" Dockerfile
grep -n -A4 "tool.uv.workspace" pyproject.tomlThen find the line you see in this list and open its fix:
- 1Workspace member pyproject.toml files are not in the image yet
pyproject.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 - 2The image runs a different uv release than the one that wrote uv.lock
The 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.
grep -n -E "COPY|uv sync|mount=type=bind" DockerfileFix
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.
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 --lockedVerify
docker build completes both sync steps, and the final --locked sync passes because every member is present.
docker build --no-cache -t myapp .Confirmed by docs.astral.sh
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.
grep -n "astral-sh/uv" DockerfileFix
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.
# 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.
uv lock --check && docker build -t myapp .Confirmed by docs.astral.sh
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.