Use short image ID for image volume mount source - #14030
Conversation
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>
a6d3ea5 to
8bb5177
Compare
|
Removed Force-pushed the branch ( |
|
Closing as superseded. Issue #14005 is already fixed on
|
What I did
Fixes #14005.
docker compose upfails to create a container that mounts atype: imagevolume with
Error response from daemon: No such image: sha256:<digest>when thereferenced image is already present locally (either built by the project or
pulled on a previous run). openQA caught this via
TestImageVolumeandTestImageVolumeRecreateOnRebuild.Root cause.
resolveImageVolumes(pkg/compose/build.go) set the volumemount source to the full image ID (
sha256:<digest>). The engine does notaccept that reference form as a
type=imagemount source, so the create call isrejected. The full ID had been chosen over
name@digest(which fails forlocal-only images without RepoDigests) and to make
ServiceHashchange onrebuild — 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 theresolved source is not the
sha256:reference form.RED — on the unmodified
mainbranch (before the fix):GREEN — with the fix:
Real-world validation against the engine
Building an image and requesting a
type=imagemount through the Engine API(daemon 29.1.3), using the source form Compose produced before vs. after this
change:
Validation
golangci-lint run --build-tags e2e ./...→0 issues.go test $(go list ./... | grep -vE '/e2e')) pass;pkg/composegreen. No new failures versus the
mainbaseline.