@@ -24,12 +24,14 @@ import (
24
24
"sort"
25
25
"strconv"
26
26
"strings"
27
+ "time"
27
28
28
29
"github.com/docker/compose/v2/cmd/formatter"
29
30
"github.com/docker/compose/v2/pkg/utils"
30
31
"github.com/docker/docker/api/types"
31
32
32
33
formatter2 "github.com/docker/cli/cli/command/formatter"
34
+ "github.com/docker/go-units"
33
35
"github.com/pkg/errors"
34
36
"github.com/spf13/cobra"
35
37
@@ -142,21 +144,18 @@ SERVICES:
142
144
143
145
return formatter .Print (containers , opts .Format , os .Stdout ,
144
146
writer (containers ),
145
- "NAME" , "COMMAND" , "SERVICE" , "STATUS" , "PORTS" )
147
+ "NAME" , "IMAGE" , " COMMAND" , "SERVICE" , "CREATED " , "STATUS" , "PORTS" )
146
148
}
147
149
148
150
func writer (containers []api.ContainerSummary ) func (w io.Writer ) {
149
151
return func (w io.Writer ) {
150
152
for _ , container := range containers {
151
153
ports := displayablePorts (container )
152
- status := container .State
153
- if status == "running" && container .Health != "" {
154
- status = fmt .Sprintf ("%s (%s)" , container .State , container .Health )
155
- } else if status == "exited" || status == "dead" {
156
- status = fmt .Sprintf ("%s (%d)" , container .State , container .ExitCode )
157
- }
154
+ createdAt := time .Unix (container .Created , 0 )
155
+ created := units .HumanDuration (time .Now ().UTC ().Sub (createdAt )) + " ago"
156
+ status := container .Status
158
157
command := formatter2 .Ellipsis (container .Command , 20 )
159
- _ , _ = fmt .Fprintf (w , "%s\t %s\t %s\t %s\t %s\n " , container .Name , strconv .Quote (command ), container .Service , status , ports )
158
+ _ , _ = fmt .Fprintf (w , "%s\t %s\t %s\t %s\t %s\t %s \t %s \ n " , container .Name , container . Image , strconv .Quote (command ), container .Service , created , status , ports )
160
159
}
161
160
}
162
161
}
0 commit comments