MCPcopy Index your code
hub / github.com/docker/cli / Image

Method Image

cli/command/formatter/container.go:182–213  ·  view source on GitHub ↗

Image returns the container's image reference. If the trunc option is set, the image's registry digest can be included.

()

Source from the content-addressed store, hash-verified

180// Image returns the container's image reference. If the trunc option is set,
181// the image's registry digest can be included.
182func (c *ContainerContext) Image() string {
183 if c.c.Image == "" {
184 return "<no image>"
185 }
186 if !c.trunc {
187 return c.c.Image
188 }
189 if trunc := TruncateID(c.c.ImageID); trunc == TruncateID(c.c.Image) {
190 return trunc
191 }
192 ref, err := reference.ParseNormalizedNamed(c.c.Image)
193 if err != nil {
194 return c.c.Image
195 }
196
197 if _, ok := ref.(reference.Digested); ok {
198 // strip the digest, but preserve the tag (if any)
199 var tag string
200 if t, ok := ref.(reference.Tagged); ok {
201 tag = t.Tag()
202 }
203 ref = reference.TrimNamed(ref)
204 if tag != "" {
205 if out, err := reference.WithTag(ref, tag); err == nil {
206 ref = out
207 }
208 }
209 }
210
211 // Format as "familiar" name with "docker.io[/library]" trimmed.
212 return reference.FamiliarString(ref)
213}
214
215// Command returns's the container's command. If the trunc option is set, the
216// returned command is truncated (ellipsized).

Callers

nothing calls this directly

Calls 2

TruncateIDFunction · 0.85
TagMethod · 0.45

Tested by

no test coverage detected