mirror of
https://github.com/docker/compose.git
synced 2025-07-23 21:54:40 +02:00
Get the real status of containers
This commit is contained in:
parent
02526dec84
commit
885fd799e1
@ -53,7 +53,6 @@ func New(ctx context.Context) (containers.ContainerService, error) {
|
|||||||
func (cs *containerService) List(ctx context.Context) ([]containers.Container, error) {
|
func (cs *containerService) List(ctx context.Context) ([]containers.Container, error) {
|
||||||
var cg []containerinstance.ContainerGroup
|
var cg []containerinstance.ContainerGroup
|
||||||
result, err := cs.cgc.ListByResourceGroup(ctx, cs.ctx.ResourceGroup)
|
result, err := cs.cgc.ListByResourceGroup(ctx, cs.ctx.ResourceGroup)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []containers.Container{}, err
|
return []containers.Container{}, err
|
||||||
}
|
}
|
||||||
@ -67,12 +66,20 @@ func (cs *containerService) List(ctx context.Context) ([]containers.Container, e
|
|||||||
|
|
||||||
res := []containers.Container{}
|
res := []containers.Container{}
|
||||||
for _, c := range cg {
|
for _, c := range cg {
|
||||||
cc := *c.Containers
|
group, err := cs.cgc.Get(ctx, cs.ctx.ResourceGroup, *c.Name)
|
||||||
for _, d := range cc {
|
if err != nil {
|
||||||
|
return []containers.Container{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, d := range *group.Containers {
|
||||||
|
status := "Unknown"
|
||||||
|
if d.InstanceView != nil && d.InstanceView.CurrentState != nil {
|
||||||
|
status = *d.InstanceView.CurrentState.State
|
||||||
|
}
|
||||||
res = append(res, containers.Container{
|
res = append(res, containers.Container{
|
||||||
ID: *c.Name,
|
ID: *d.Name,
|
||||||
Image: *d.Image,
|
Image: *d.Image,
|
||||||
// Command: strings.Join(*d.ContainerProperties.Command, " "), // TODO command can be null
|
Status: status,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,10 +27,10 @@ var PsCommand = cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
|
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
|
||||||
fmt.Fprintf(w, "NAME\tIMAGE\tCOMMAND\n")
|
fmt.Fprintf(w, "NAME\tIMAGE\tSTATUS\tCOMMAND\n")
|
||||||
format := "%s\t%s\t%s\n"
|
format := "%s\t%s\t%s\t%s\n"
|
||||||
for _, c := range containers {
|
for _, c := range containers {
|
||||||
fmt.Fprintf(w, format, c.ID, c.Image, c.Command)
|
fmt.Fprintf(w, format, c.ID, c.Image, c.Status, c.Command)
|
||||||
}
|
}
|
||||||
return w.Flush()
|
return w.Flush()
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user