Skip to content

imagetools inspect --format ignores formatting unless json is used #1175

Closed

Description

@thaJeztah

Was writing a reply to docker/hub-feedback#2043, and noticed this.

Reproduced on;

docker buildx version
github.com/docker/buildx v0.8.2-docker 6224def4dd2c3d347eee19db595348c50d7cb491

When using the -f / --format option, the template is ignored, unless it's using the json function;

docker buildx imagetools inspect --format '{{.Manifest.Digest}}' tensorflow/tensorflow:1.13.1-gpu-py3
Name:      docker.io/tensorflow/tensorflow:1.13.1-gpu-py3
MediaType: application/vnd.docker.distribution.manifest.v2+json
Digest:    sha256:0f949ccc690d9c50e9b46b16d9030c2c6845af621c2e7e82c4bf59803edc69b5
docker buildx imagetools inspect --format '{{json .Manifest.Digest}}' tensorflow/tensorflow:1.13.1-gpu-py3
"sha256:0f949ccc690d9c50e9b46b16d9030c2c6845af621c2e7e82c4bf59803edc69b5"

This is inconsistent with other commands, for example, here's docker image inspect (difference between using json and without is that the json output uses JSON quoting for the output);

docker image inspect -f '{{.ID}}' busybox
sha256:62aedd01bd8520c43d06b09f7a0f67ba9720bdc04631a8242c65ea995f3ecac8

docker image inspect -f '{{json .ID}}' busybox
"sha256:62aedd01bd8520c43d06b09f7a0f67ba9720bdc04631a8242c65ea995f3ecac8"

Also note that the json output does not print a newline at the end, which can make it a bit cumbersome to use; here's the full output (notice that the prompt is appended to the output, because there's no trailing newline)

root@swarm-test-01:~# docker buildx imagetools inspect --format '{{json .Manifest.Digest}}' tensorflow/tensorflow:1.13.1-gpu-py3
"sha256:0f949ccc690d9c50e9b46b16d9030c2c6845af621c2e7e82c4bf59803edc69b5"root@swarm-test-01:~#

Activity

  1. thaJeztah commented on Jun 21, 2022

    @thaJeztah
    MemberAuthor
  2. crazy-max commented on Jun 21, 2022

    @crazy-max
    Member

    @thaJeztah Since docker/cli#2936 has been merged I will revisit the format output to be aligned.

  3. thaJeztah commented on Jun 21, 2022

    @thaJeztah
    MemberAuthor

    Thanks! Yeah, I was mostly surprised it was silently ignored 😅. w.r.t. the newline at the end; technically it's "correct" (the newline doesn't have to be there (also not when using it for scripting), but ISTR the newline was added to make it slightly easier to use interactively.

  4. uhthomas commented on Jun 13, 2023

    @uhthomas

    Hey! It looks like this issue is coming up on a year old, is this fixable now given the aforementioned PR was merged? I still see this behaviour today.

    ❯ docker buildx imagetools inspect debian:bullseye --format="{{.Manifest.Digest}}"
    Name:      docker.io/library/debian:bullseye
    MediaType: application/vnd.docker.distribution.manifest.list.v2+json
    Digest:    sha256:1e5f2d70c9441c971607727f56d0776fb9eecf23cd37b595b26db7a974b2301d
               
    Manifests:
    ...
  5. thaJeztah commented on Jun 13, 2023

    @thaJeztah
    MemberAuthor

    The linked PR was implementing changes in the docker CLI itself; this probably hasn't been worked on for buildx. Contributions welcome though if someone is interested working on this.

  6. uhthomas commented on Jun 14, 2023

    @uhthomas

    Sure, I'm taking a look now. There's definitely something funky going on given it doesn't seem that Go templates for {{.Manifest are respected and includes duplicate logic.

  7. uhthomas commented on Jun 14, 2023

    @uhthomas

    Cool, I removed that logic and it seems to work as expected. I'll clean it up and submit a PR.

    ❯ go run ./cmd/buildx imagetools inspect --format="{{.Manifest.Digest}}" alpine
    sha256:02bb6f428431fbc2809c5d1b41eab5a68350194fb508869a33cb1af4444c9b11
  8. added 3 commits that reference this issue on Jun 14, 2023
    58baf9e
    2e29672
    cd95d32
  9. segevfiner commented on Sep 17, 2025

    @segevfiner

    Using --format '{{printf "%s" .Manifest.Digest}}' also seems to work. Until this is fixed, that is.

  10. added theissue type on Mar 12, 2026
  11. crazy-max commented on Sep 3, 2026

    @crazy-max
    Member

    Fixed in v0.33.0 (#3721 and 78439e2): the {{.Manifest... prefix check that treated any template starting with .Manifest as "print the whole manifest" was replaced by an exact match for {{.Manifest}}, so templates like {{.Manifest.Digest}} are executed. --raw intentionally omits the trailing newline.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions