@@ -21,14 +21,14 @@ import (
2121const (
2222 defaultContainerTableFormat = "table {{.ID}}\t {{.Image}}\t {{.Command}}\t {{.RunningFor}}\t {{.Status}}\t {{.Ports}}\t {{.Names}}"
2323
24- namesHeader = "NAMES"
25- commandHeader = "COMMAND"
26- runningForHeader = "CREATED"
27- mountsHeader = "MOUNTS"
28- localVolumes = "LOCAL VOLUMES"
29- networksHeader = "NETWORKS"
30- platformHeader = "PLATFORM"
31- healthCheckHeader = "HEALTHCHECK "
24+ namesHeader = "NAMES"
25+ commandHeader = "COMMAND"
26+ runningForHeader = "CREATED"
27+ mountsHeader = "MOUNTS"
28+ localVolumes = "LOCAL VOLUMES"
29+ networksHeader = "NETWORKS"
30+ platformHeader = "PLATFORM"
31+ healthStatusHeader = "HEALTH STATUS "
3232)
3333
3434// Platform wraps a [ocispec.Platform] to implement the stringer interface.
@@ -122,7 +122,7 @@ func NewContainerContext() *ContainerContext {
122122 "LocalVolumes" : localVolumes ,
123123 "Networks" : networksHeader ,
124124 "Platform" : platformHeader ,
125- "HealthCheck " : healthCheckHeader ,
125+ "HealthStatus " : healthStatusHeader ,
126126 }
127127 return & containerCtx
128128}
@@ -354,25 +354,32 @@ func (c *ContainerContext) Networks() string {
354354 return strings .Join (networks , "," )
355355}
356356
357- // HealthCheck returns the container's health status (for example, "healthy","unhealthy", or "starting").
357+ // HealthStatus returns the container's health status (for example, "healthy","unhealthy", or "starting").
358358// If no healthcheck is configured, an empty
359359// string is returned.
360- func (c * ContainerContext ) HealthCheck () string {
360+ func (c * ContainerContext ) HealthStatus () string {
361361 if c .c .Health != nil && c .c .Health .Status != "" {
362362 return string (c .c .Health .Status )
363363 }
364364
365- // Fallback for daemons/API versions that include health only in Status text.
366- switch {
367- case strings .HasSuffix (c .c .Status , "(healthy)" ):
368- return string (container .Healthy )
369- case strings .HasSuffix (c .c .Status , "(unhealthy)" ):
370- return string (container .Unhealthy )
371- case strings .HasSuffix (c .c .Status , "(health: starting)" ):
372- return string (container .Starting )
365+ // Fallback for API versions before v1.52, which include health only in Status text;
366+ // see https://github.com/moby/moby/pull/50281
367+ // see https://github.com/moby/moby/blob/docker-v29.4.3/daemon/container/health.go#L18-L43
368+ _ , health , ok := strings .Cut (c .c .Status , "(" )
369+ if ! ok || ! strings .HasSuffix (health , ")" ) {
370+ return ""
373371 }
374372
375- return ""
373+ health = strings .TrimSuffix (health , ")" )
374+ health = strings .TrimPrefix (health , "health: " )
375+
376+ parsedHealth := container .HealthStatus (health )
377+ switch parsedHealth {
378+ case container .Healthy , container .Unhealthy , container .Starting :
379+ return health
380+ default :
381+ return ""
382+ }
376383}
377384
378385// DisplayablePorts returns formatted string representing open ports of container
0 commit comments