Skip to content

Commit bc568ee

Browse files
committed
align compose ps output with docker ps
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent a501ab3 commit bc568ee

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

cmd/compose/ps.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ import (
2424
"sort"
2525
"strconv"
2626
"strings"
27+
"time"
2728

2829
"github.com/docker/compose/v2/cmd/formatter"
2930
"github.com/docker/compose/v2/pkg/utils"
3031
"github.com/docker/docker/api/types"
3132

3233
formatter2 "github.com/docker/cli/cli/command/formatter"
34+
"github.com/docker/go-units"
3335
"github.com/pkg/errors"
3436
"github.com/spf13/cobra"
3537

@@ -142,21 +144,18 @@ SERVICES:
142144

143145
return formatter.Print(containers, opts.Format, os.Stdout,
144146
writer(containers),
145-
"NAME", "COMMAND", "SERVICE", "STATUS", "PORTS")
147+
"NAME", "IMAGE", "COMMAND", "SERVICE", "CREATED", "STATUS", "PORTS")
146148
}
147149

148150
func writer(containers []api.ContainerSummary) func(w io.Writer) {
149151
return func(w io.Writer) {
150152
for _, container := range containers {
151153
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
158157
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)
160159
}
161160
}
162161
}

pkg/api/api.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,13 @@ type PortPublisher struct {
318318
type ContainerSummary struct {
319319
ID string
320320
Name string
321+
Image any
321322
Command string
322323
Project string
323324
Service string
325+
Created int64
324326
State string
327+
Status string
325328
Health string
326329
ExitCode int
327330
Publishers PortPublishers

pkg/compose/ps.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,13 @@ func (s *composeService) Ps(ctx context.Context, projectName string, options api
9191
summary[i] = api.ContainerSummary{
9292
ID: container.ID,
9393
Name: getCanonicalContainerName(container),
94+
Image: container.Image,
9495
Project: container.Labels[api.ProjectLabel],
9596
Service: container.Labels[api.ServiceLabel],
9697
Command: container.Command,
9798
State: container.State,
99+
Status: container.Status,
100+
Created: container.Created,
98101
Health: health,
99102
ExitCode: exitCode,
100103
Publishers: publishers,

0 commit comments

Comments
 (0)