diff --git a/cmd/compose/ps.go b/cmd/compose/ps.go index 94dd1a9d1..cfaf46c96 100644 --- a/cmd/compose/ps.go +++ b/cmd/compose/ps.go @@ -24,12 +24,14 @@ import ( "sort" "strconv" "strings" + "time" "github.com/docker/compose/v2/cmd/formatter" "github.com/docker/compose/v2/pkg/utils" "github.com/docker/docker/api/types" formatter2 "github.com/docker/cli/cli/command/formatter" + "github.com/docker/go-units" "github.com/pkg/errors" "github.com/spf13/cobra" @@ -142,21 +144,18 @@ SERVICES: return formatter.Print(containers, opts.Format, os.Stdout, writer(containers), - "NAME", "COMMAND", "SERVICE", "STATUS", "PORTS") + "NAME", "IMAGE", "COMMAND", "SERVICE", "CREATED", "STATUS", "PORTS") } func writer(containers []api.ContainerSummary) func(w io.Writer) { return func(w io.Writer) { for _, container := range containers { ports := displayablePorts(container) - status := container.State - if status == "running" && container.Health != "" { - status = fmt.Sprintf("%s (%s)", container.State, container.Health) - } else if status == "exited" || status == "dead" { - status = fmt.Sprintf("%s (%d)", container.State, container.ExitCode) - } + createdAt := time.Unix(container.Created, 0) + created := units.HumanDuration(time.Now().UTC().Sub(createdAt)) + " ago" + status := container.Status command := formatter2.Ellipsis(container.Command, 20) - _, _ = fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", container.Name, strconv.Quote(command), container.Service, status, ports) + _, _ = 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) } } } diff --git a/pkg/api/api.go b/pkg/api/api.go index 0fb6597b2..805c833ce 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -318,10 +318,13 @@ type PortPublisher struct { type ContainerSummary struct { ID string Name string + Image any Command string Project string Service string + Created int64 State string + Status string Health string ExitCode int Publishers PortPublishers diff --git a/pkg/compose/ps.go b/pkg/compose/ps.go index 7df826a08..4c7eaac98 100644 --- a/pkg/compose/ps.go +++ b/pkg/compose/ps.go @@ -91,10 +91,13 @@ func (s *composeService) Ps(ctx context.Context, projectName string, options api summary[i] = api.ContainerSummary{ ID: container.ID, Name: getCanonicalContainerName(container), + Image: container.Image, Project: container.Labels[api.ProjectLabel], Service: container.Labels[api.ServiceLabel], Command: container.Command, State: container.State, + Status: container.Status, + Created: container.Created, Health: health, ExitCode: exitCode, Publishers: publishers,