diff --git a/cmd/compose/ps.go b/cmd/compose/ps.go
index b19a0c6245..c8d1f448ea 100644
--- a/cmd/compose/ps.go
+++ b/cmd/compose/ps.go
@@ -81,7 +81,7 @@ func psCommand(p *ProjectOptions, dockerCli command.Cli, backendOptions *Backend
ValidArgsFunction: completeServiceNames(dockerCli, p),
}
flags := psCmd.Flags()
- flags.StringVar(&opts.Format, "format", "table", cliflags.FormatHelp)
+ flags.StringVar(&opts.Format, "format", "", cliflags.FormatHelp)
flags.StringVar(&opts.Filter, "filter", "", "Filter services by a property (supported filters: status)")
flags.StringArrayVar(&opts.Status, "status", []string{}, "Filter services by status. Values: [paused | restarting | removing | running | dead | created | exited]")
flags.BoolVarP(&opts.Quiet, "quiet", "q", false, "Only display IDs")
diff --git a/docs/reference/compose_ps.md b/docs/reference/compose_ps.md
index 54305e2157..71962d1d1c 100644
--- a/docs/reference/compose_ps.md
+++ b/docs/reference/compose_ps.md
@@ -25,7 +25,7 @@ example-bar-1 alpine "/entrypoint.…" bar 4 seconds ago exited
| `-a`, `--all` | `bool` | | Show all stopped containers (including those created by the run command) |
| `--dry-run` | `bool` | | Execute command in dry run mode |
| [`--filter`](#filter) | `string` | | Filter services by a property (supported filters: status) |
-| [`--format`](#format) | `string` | `table` | Format output using a custom template:
'table': Print output in table format with column headers (default)
'table TEMPLATE': Print output in table format using the given Go template
'json': Print in JSON format
'TEMPLATE': Print output using the given Go template.
Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates |
+| [`--format`](#format) | `string` | | Format output using a custom template:
'table': Print output in table format with column headers (default)
'table TEMPLATE': Print output in table format using the given Go template
'json': Print in JSON format
'TEMPLATE': Print output using the given Go template.
Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates |
| `--no-trunc` | `bool` | | Don't truncate output |
| `--orphans` | `bool` | `true` | Include orphaned services (not declared by project) |
| `-q`, `--quiet` | `bool` | | Only display IDs |
diff --git a/docs/reference/docker_compose_ps.yaml b/docs/reference/docker_compose_ps.yaml
index 9f8d4ba447..d42f24182a 100644
--- a/docs/reference/docker_compose_ps.yaml
+++ b/docs/reference/docker_compose_ps.yaml
@@ -45,7 +45,6 @@ options:
swarm: false
- option: format
value_type: string
- default_value: table
description: |-
Format output using a custom template:
'table': Print output in table format with column headers (default)
diff --git a/pkg/e2e/ps_test.go b/pkg/e2e/ps_test.go
index 26e799d679..8ea47f7463 100644
--- a/pkg/e2e/ps_test.go
+++ b/pkg/e2e/ps_test.go
@@ -18,8 +18,11 @@ package e2e
import (
"encoding/json"
+ "os"
+ "path/filepath"
"strings"
"testing"
+ "time"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
@@ -133,3 +136,22 @@ func TestPs(t *testing.T) {
res.Assert(t, icmd.Expected{ExitCode: 1, Err: "no such service: unknown"})
})
}
+
+// #13643: compose ps did not honor psFormat from Docker config when no
+// --format flag was given; the flag defaulted to "table", preventing the
+// empty-string check from firing.
+func TestPsHonorsPsFormat(t *testing.T) {
+ s := NewScenario(t, "compose ps must apply psFormat from Docker CLI config when no --format flag is given")
+ // Write psFormat into the CLI's config dir, which already holds the
+ // test-built compose binary in cli-plugins/. Redirecting DOCKER_CONFIG
+ // via s.Env() to a separate directory would strip those plugins, causing
+ // docker compose to fall back to the system binary that predates the fix.
+ assert.NilError(t, os.WriteFile(filepath.Join(s.CLI().ConfigDir, "config.json"), []byte(`{"psFormat":"table {{.Name}}"}`), 0o600))
+ s.Step("service starts",
+ ComposeCmd("up", "-d"),
+ Eventually(ServiceState("app", "running"), 10*time.Second)).
+ Step("ps without --format renders only the NAME column from psFormat",
+ ComposeCmd("ps"),
+ OutputContains("NAME"),
+ OutputNotContains("IMAGE"))
+}
diff --git a/pkg/e2e/testdata/TestPsHonorsPsFormat/compose.yaml b/pkg/e2e/testdata/TestPsHonorsPsFormat/compose.yaml
new file mode 100644
index 0000000000..28bbf0248d
--- /dev/null
+++ b/pkg/e2e/testdata/TestPsHonorsPsFormat/compose.yaml
@@ -0,0 +1,4 @@
+services:
+ app:
+ image: busybox
+ command: sleep infinity