Skip to content

Use short image ID for image volume mount source - #14030

Open
ousamabenyounes wants to merge 1 commit into
docker:mainfrom
ousamabenyounes:fix/issue-14005
Open

Use short image ID for image volume mount source#14030
ousamabenyounes wants to merge 1 commit into
docker:mainfrom
ousamabenyounes:fix/issue-14005

Conversation

@ousamabenyounes

Copy link
Copy Markdown

What I did

Fixes #14005.

docker compose up fails to create a container that mounts a type: image
volume with Error response from daemon: No such image: sha256:<digest> when the
referenced image is already present locally (either built by the project or
pulled on a previous run). openQA caught this via TestImageVolume and
TestImageVolumeRecreateOnRebuild.

Root cause. resolveImageVolumes (pkg/compose/build.go) set the volume
mount source to the full image ID (sha256:<digest>). The engine does not
accept that reference form as a type=image mount source, so the create call is
rejected. The full ID had been chosen over name@digest (which fails for
local-only images without RepoDigests) and to make ServiceHash change on
rebuild — but the full-ID form itself is what the daemon rejects.

Fix. Resolve the source to the short image ID via stringid.TruncateID
(already used elsewhere in the repo). The short form is accepted by the daemon,
still has no RepoDigest dependency, and still changes whenever the image is
rebuilt, so recreate-on-rebuild behaviour is preserved.

Related issue

| Issues | Fixes #14005

Test verification (RED → GREEN)

New unit test TestResolveImageVolumes (pkg/compose/build_test.go) asserts the
resolved source is not the sha256: reference form.

RED — on the unmodified main branch (before the fix):

=== RUN   TestResolveImageVolumes
    build_test.go:167: assertion failed: strings.HasPrefix(source, "sha256:") is true:
    image volume source "sha256:26a04b05e50737f5d07b282e87da9c7b6eb061fc7b955243916e6792d007d353"
    must not use the sha256: reference form rejected by the engine
--- FAIL: TestResolveImageVolumes (0.00s)
FAIL	github.com/docker/compose/v5/pkg/compose

GREEN — with the fix:

=== RUN   TestResolveImageVolumes
--- PASS: TestResolveImageVolumes (0.00s)
ok  	github.com/docker/compose/v5/pkg/compose	0.027s

Real-world validation against the engine

Building an image and requesting a type=image mount through the Engine API
(daemon 29.1.3), using the source form Compose produced before vs. after this
change:

OLD form (source = full sha256 image ID, pre-fix):
  [create REJECTED]  failed to mount ... (engine refuses the sha256:<digest> source)

NEW form (source = short image ID "26a04b05e507", post-fix):
  mount OK (container start HTTP 204)

Validation

  • golangci-lint run --build-tags e2e ./...0 issues.
  • Unit tests (go test $(go list ./... | grep -vE '/e2e')) pass; pkg/compose
    green. No new failures versus the main baseline.

@ousamabenyounes
ousamabenyounes requested review from a team as code owners August 11, 2026 23:28
The full "sha256:<digest>" image ID form is rejected by the engine as a
`type=image` volume mount source, so containers that mount a locally
present image fail with "No such image: sha256:<digest>". Truncate the
resolved image ID to the short form the daemon accepts; it still changes
on rebuild, keeping ServiceHash recreate semantics intact.

Fixes docker#14005

Signed-off-by: Ben Younes <2910651+ousamabenyounes@users.noreply.github.com>
@ousamabenyounes

Copy link
Copy Markdown
Author

Removed AI_AGENT_DISCLOSURE.md from the commit and rebased onto the latest main. Reviewed the change myself before dropping the marker file.

Force-pushed the branch (a6d3ea57f8bb517722).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] type=image volumes fail with "No such image" when the source image is already present locally

1 participant