-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix(image): don't treat digest-only images as dangling in list output #6960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
0015f6c
cbeeefe
397a379
044dea2
e2abd26
477b5d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -364,6 +364,24 @@ func DisplayablePorts(ports []container.PortSummary) string { | |
| var result []string | ||
| var hostMappings []string | ||
| var groupMapKeys []string | ||
|
|
||
| // Pre-pass: record which (hostPort, privatePort, proto) tuples have an | ||
| // IPv4 wildcard (0.0.0.0) binding. Used below to suppress the matching | ||
| // IPv6 wildcard (::) entry, avoiding duplicate output such as: | ||
| // 0.0.0.0:8080->80/tcp, :::8080->80/tcp | ||
| // See: https://github.com/docker/cli/issues/6869 | ||
| type mappingKey struct { | ||
| hostPort uint16 | ||
| privatePort uint16 | ||
| proto string | ||
| } | ||
| ipv4Bindings := make(map[mappingKey]bool) | ||
| for _, port := range ports { | ||
| if port.IP.String() == "0.0.0.0" && port.PublicPort != 0 { | ||
| ipv4Bindings[mappingKey{port.PublicPort, port.PrivatePort, port.Type}] = true | ||
| } | ||
| } | ||
|
|
||
|
Comment on lines
+368
to
+384
|
||
| sort.Slice(ports, func(i, j int) bool { | ||
| return comparePorts(ports[i], ports[j]) | ||
| }) | ||
|
|
@@ -373,6 +391,18 @@ func DisplayablePorts(ports []container.PortSummary) string { | |
| portKey := port.Type | ||
| if port.IP.IsValid() { | ||
| if port.PublicPort != current { | ||
| // Suppress the IPv6 wildcard entry when an IPv4 wildcard | ||
| // entry already covers the same (hostPort, privatePort, proto) | ||
| // tuple. This merges: | ||
| // 0.0.0.0:8080->80/tcp, :::8080->80/tcp | ||
| // into the cleaner: | ||
| // 0.0.0.0:8080->80/tcp | ||
| if port.IP.Is6() && !port.IP.Is4In6() && port.IP.IsUnspecified() { | ||
| key := mappingKey{port.PublicPort, port.PrivatePort, port.Type} | ||
| if ipv4Bindings[key] { | ||
| continue | ||
| } | ||
| } | ||
|
Comment on lines
368
to
+405
|
||
| hAddrPort := net.JoinHostPort(port.IP.String(), strconv.Itoa(int(port.PublicPort))) | ||
| hostMappings = append(hostMappings, fmt.Sprintf("%s->%d/%s", hAddrPort, port.PrivatePort, port.Type)) | ||
| continue | ||
|
|
@@ -435,4 +465,4 @@ func comparePorts(i, j container.PortSummary) bool { | |
| } | ||
|
|
||
| return i.Type < j.Type | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -176,7 +176,7 @@ func shouldUseTree(options imagesOptions) (bool, error) { | |
|
|
||
| // isDangling is a copy of [formatter.isDangling]. | ||
| func isDangling(img image.Summary) bool { | ||
| if len(img.RepoTags) == 0 { | ||
| if len(img.RepoTags) == 0 && len(img.RepoDigests) == 0 { | ||
| return true | ||
| } | ||
| return len(img.RepoTags) == 1 && img.RepoTags[0] == "<none>:<none>" && len(img.RepoDigests) == 1 && img.RepoDigests[0] == "<none>@<none>" | ||
|
Comment on lines
+179
to
182
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The newly added comment examples show IPv6 wildcard bindings as
:::8080->80/tcp, but the actual formatting produced here uses net.JoinHostPort, which renders IPv6 as[::]:8080->80/tcp(see existing tests expecting[::1]:...). Please update the examples so they match real output and avoid confusion when reading this code.