@@ -565,18 +565,21 @@ func ListContainers(client pb.RuntimeServiceClient, opts listOptions) error {
565
565
}
566
566
if opts .state != "" {
567
567
st .State = pb .ContainerState_CONTAINER_UNKNOWN
568
- switch opts .state {
568
+ switch strings . ToLower ( opts .state ) {
569
569
case "created" :
570
570
st .State = pb .ContainerState_CONTAINER_CREATED
571
571
filter .State = st
572
572
case "running" :
573
573
st .State = pb .ContainerState_CONTAINER_RUNNING
574
574
filter .State = st
575
- case "stopped " :
575
+ case "exited " :
576
576
st .State = pb .ContainerState_CONTAINER_EXITED
577
577
filter .State = st
578
+ case "unknown" :
579
+ st .State = pb .ContainerState_CONTAINER_UNKNOWN
580
+ filter .State = st
578
581
default :
579
- log .Fatalf ("--state should be one of created, running or stopped " )
582
+ log .Fatalf ("--state should be one of created, running, exited or unknown " )
580
583
}
581
584
}
582
585
if opts .latest || opts .last > 0 {
@@ -625,7 +628,7 @@ func ListContainers(client pb.RuntimeServiceClient, opts listOptions) error {
625
628
}
626
629
}
627
630
fmt .Fprintf (w , "%s\t %s\t %s\t %s\t %s\t %d\n " ,
628
- id , c .Image .Image , ctm , c .State , c .Metadata .Name , c .Metadata .Attempt )
631
+ id , c .Image .Image , ctm , convertContainerState ( c .State ) , c .Metadata .Name , c .Metadata .Attempt )
629
632
continue
630
633
}
631
634
@@ -637,7 +640,7 @@ func ListContainers(client pb.RuntimeServiceClient, opts listOptions) error {
637
640
}
638
641
fmt .Printf ("Attempt: %v\n " , c .Metadata .Attempt )
639
642
}
640
- fmt .Printf ("State: %s\n " , c .State )
643
+ fmt .Printf ("State: %s\n " , convertContainerState ( c .State ) )
641
644
if c .Image != nil {
642
645
fmt .Printf ("Image: %s\n " , c .Image .Image )
643
646
}
@@ -661,6 +664,22 @@ func ListContainers(client pb.RuntimeServiceClient, opts listOptions) error {
661
664
return nil
662
665
}
663
666
667
+ func convertContainerState (state pb.ContainerState ) string {
668
+ switch state {
669
+ case pb .ContainerState_CONTAINER_CREATED :
670
+ return "Created"
671
+ case pb .ContainerState_CONTAINER_RUNNING :
672
+ return "Running"
673
+ case pb .ContainerState_CONTAINER_EXITED :
674
+ return "Exited"
675
+ case pb .ContainerState_CONTAINER_UNKNOWN :
676
+ return "Unknown"
677
+ default :
678
+ log .Fatalf ("Unknown container state %q" , state )
679
+ return ""
680
+ }
681
+ }
682
+
664
683
func getContainersList (containersList []* pb.Container , opts listOptions ) []* pb.Container {
665
684
sort .Sort (containerByCreated (containersList ))
666
685
n := len (containersList )
0 commit comments