Browse code

Fix issue of filter in `docker ps` where `health=starting` returns nothing

This fix tries to address the issue raised in 35920 where the filter
of `docker ps` with `health=starting` always returns nothing.

The issue was that in container view, the human readable string (`HealthString()` => `Health.String()`)
of health status was used. In case of starting it is `"health: starting"`.
However, the filter still uses `starting` so no match returned.

This fix fixes the issue by using `container.Health.Status()` instead so that it matches
the string (`starting`) passed by filter.

This fix fixes 35920.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

Yong Tang authored on 2018/01/05 13:33:42
Showing 1 changed files
... ...
@@ -295,6 +295,10 @@ func (v *memdbView) GetAllNames() map[string][]string {
295 295
 // transform maps a (deep) copied Container object to what queries need.
296 296
 // A lock on the Container is not held because these are immutable deep copies.
297 297
 func (v *memdbView) transform(container *Container) *Snapshot {
298
+	health := types.NoHealthcheck
299
+	if container.Health != nil {
300
+		health = container.Health.Status()
301
+	}
298 302
 	snapshot := &Snapshot{
299 303
 		Container: types.Container{
300 304
 			ID:      container.ID,
... ...
@@ -313,7 +317,7 @@ func (v *memdbView) transform(container *Container) *Snapshot {
313 313
 		Managed:      container.Managed,
314 314
 		ExposedPorts: make(nat.PortSet),
315 315
 		PortBindings: make(nat.PortSet),
316
-		Health:       container.HealthString(),
316
+		Health:       health,
317 317
 		Running:      container.Running,
318 318
 		Paused:       container.Paused,
319 319
 		ExitCode:     container.ExitCode(),