1
0
mirror of https://github.com/docker/cli.git synced 2026-01-13 18:22:35 +03:00

cli/command/formatter: ContainerContext.Image: explicitly strip digest

The `reference.TrimNamed` function strips both digests and tags; the
formatter function only wants to remove the digest, but preserve any
tags present.

Update the implementation to only trim the reference if there's a digest
present, otherwise use it as-is.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-08-24 15:50:31 +02:00
parent 7ac3e0e0bf
commit 4f944e245b

View File

@@ -181,18 +181,22 @@ func (c *ContainerContext) Image() string {
return c.c.Image
}
if nt, ok := ref.(reference.NamedTagged); ok {
// strip the digest, but preserve the tag
if namedTagged, err := reference.WithTag(reference.TrimNamed(nt), nt.Tag()); err == nil {
return reference.FamiliarString(namedTagged)
if _, ok := ref.(reference.Digested); ok {
// strip the digest, but preserve the tag (if any)
var tag string
if t, ok := ref.(reference.Tagged); ok {
tag = t.Tag()
}
ref = reference.TrimNamed(ref)
if tag != "" {
if out, err := reference.WithTag(ref, tag); err == nil {
ref = out
}
}
} else {
// case for when a tag is not provided
named := reference.TrimNamed(ref)
return reference.FamiliarString(named)
}
return c.c.Image
// Format as "familiar" name with "docker.io[/library]" trimmed.
return reference.FamiliarString(ref)
}
// Command returns's the container's command. If the trunc option is set, the