瀏覽代碼

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 7 年之前
父節點
當前提交
97b16aecf9
共有 1 個文件被更改,包括 5 次插入1 次删除
  1. 5 1
      container/view.go

+ 5 - 1
container/view.go

@@ -295,6 +295,10 @@ func (v *memdbView) GetAllNames() map[string][]string {
 // transform maps a (deep) copied Container object to what queries need.
 // transform maps a (deep) copied Container object to what queries need.
 // A lock on the Container is not held because these are immutable deep copies.
 // A lock on the Container is not held because these are immutable deep copies.
 func (v *memdbView) transform(container *Container) *Snapshot {
 func (v *memdbView) transform(container *Container) *Snapshot {
+	health := types.NoHealthcheck
+	if container.Health != nil {
+		health = container.Health.Status()
+	}
 	snapshot := &Snapshot{
 	snapshot := &Snapshot{
 		Container: types.Container{
 		Container: types.Container{
 			ID:      container.ID,
 			ID:      container.ID,
@@ -313,7 +317,7 @@ func (v *memdbView) transform(container *Container) *Snapshot {
 		Managed:      container.Managed,
 		Managed:      container.Managed,
 		ExposedPorts: make(nat.PortSet),
 		ExposedPorts: make(nat.PortSet),
 		PortBindings: make(nat.PortSet),
 		PortBindings: make(nat.PortSet),
-		Health:       container.HealthString(),
+		Health:       health,
 		Running:      container.Running,
 		Running:      container.Running,
 		Paused:       container.Paused,
 		Paused:       container.Paused,
 		ExitCode:     container.ExitCode(),
 		ExitCode:     container.ExitCode(),