@@ -23,6 +23,7 @@ import (
2323
2424 moby "github.com/docker/docker/api/types"
2525 "github.com/docker/docker/api/types/filters"
26+ "golang.org/x/sync/errgroup"
2627
2728 "github.com/docker/compose-cli/api/compose"
2829)
@@ -38,32 +39,49 @@ func (s *composeService) Ps(ctx context.Context, projectName string, options com
3839 return nil , err
3940 }
4041
41- var summary []compose.ContainerSummary
42- for _ , c := range containers {
43- var publishers []compose.PortPublisher
44- for _ , p := range c .Ports {
45- var url string
46- if p .PublicPort != 0 {
47- url = fmt .Sprintf ("%s:%d" , p .IP , p .PublicPort )
42+ summary := make ([]compose.ContainerSummary , len (containers ))
43+ eg , ctx := errgroup .WithContext (ctx )
44+ for i , c := range containers {
45+ container := c
46+ i := i
47+ eg .Go (func () error {
48+ var publishers []compose.PortPublisher
49+ for _ , p := range container .Ports {
50+ var url string
51+ if p .PublicPort != 0 {
52+ url = fmt .Sprintf ("%s:%d" , p .IP , p .PublicPort )
53+ }
54+ publishers = append (publishers , compose.PortPublisher {
55+ URL : url ,
56+ TargetPort : int (p .PrivatePort ),
57+ PublishedPort : int (p .PublicPort ),
58+ Protocol : p .Type ,
59+ })
60+ }
61+
62+ inspect , err := s .apiClient .ContainerInspect (ctx , container .ID )
63+ if err != nil {
64+ return err
4865 }
49- publishers = append (publishers , compose.PortPublisher {
50- URL : url ,
51- TargetPort : int (p .PrivatePort ),
52- PublishedPort : int (p .PublicPort ),
53- Protocol : p .Type ,
54- })
55- }
5666
57- summary = append (summary , compose.ContainerSummary {
58- ID : c .ID ,
59- Name : getCanonicalContainerName (c ),
60- Project : c .Labels [projectLabel ],
61- Service : c .Labels [serviceLabel ],
62- State : c .State ,
63- Publishers : publishers ,
67+ var health string
68+ if inspect .State != nil && inspect .State .Health != nil {
69+ health = inspect .State .Health .Status
70+ }
71+
72+ summary [i ] = compose.ContainerSummary {
73+ ID : container .ID ,
74+ Name : getCanonicalContainerName (container ),
75+ Project : container .Labels [projectLabel ],
76+ Service : container .Labels [serviceLabel ],
77+ State : container .State ,
78+ Health : health ,
79+ Publishers : publishers ,
80+ }
81+ return nil
6482 })
6583 }
66- return summary , nil
84+ return summary , eg . Wait ()
6785}
6886
6987func groupContainerByLabel (containers []moby.Container , labelName string ) (map [string ][]moby.Container , []string , error ) {
0 commit comments