docker: unknown command: docker compose means the Docker CLI you are running has no Compose plugin installed. The docker program works, but compose is a separate plugin binary, and there was none. Install the Compose plugin for that CLI; in the test, on Alpine, that was apk add docker-cli-compose.

The command that printed it here was the plainest one there is, docker compose version, with no compose file involved. It answered with a version number as soon as the plugin was in the CLI plugins folder.

The error

+ docker --version
Docker version 29.9.3, build 5457199aa57c45e990c59c89cab5f02b817238d7
...
+ docker compose version
docker: unknown command: docker compose

Run 'docker --help' for more information
+ echo 'exit=1'
exit=1
+ ls /usr/libexec/docker/cli-plugins
ls: /usr/libexec/docker/cli-plugins: No such file or directory

Why it happens

The message names the whole two-word command, docker compose, as unknown. Compose here is a separate binary, docker-compose, in a CLI plugins folder; the fix below shows it appearing there. Before the fix, ls on /usr/libexec/docker/cli-plugins found no such folder, because the container had only Alpine's docker-cli package, which installed docker 29.9.3. The exit code was 1.

The docker program itself was fine: docker --version in the same container printed Docker version 29.9.3 without complaint. In the first run of the script, docker compose with no subcommand at all gave the same docker: unknown command: docker compose line, also with exit code 1, so the message does not depend on what follows compose as long as no flag comes next.

With up -d instead of version, the same CLI printed a message about the flag instead; see unknown shorthand flag: 'd' in -d.

The fix

apk add --no-cache docker-cli-compose
+ ls /usr/libexec/docker/cli-plugins
docker-compose
+ docker compose version
Docker Compose version v5.6.1
+ echo 'exit=0'
+ docker compose config
exit=0

The package created the plugins folder with a docker-compose binary in it, and the same docker compose version that failed before printed Docker Compose version v5.6.1 with exit code 0. The trace interleaves the shell's + lines with output, which is why exit=0 appears after the next command's trace line.

How it was reproduced

In an alpine container of the test's own, with no Docker engine. Before the fix, only apk add docker-cli; the fix was apk add docker-cli-compose. Both runs used a small shell script with set -x, so each command shows up as a + line before its output. Versions: Docker CLI 29.9.3, Docker Compose plugin v5.6.1, both from Alpine's packages.

Frequently asked

What does docker: unknown command: docker compose mean?
The Docker CLI has no Compose plugin. In the test the CLI plugins folder did not exist; installing the Compose plugin package added docker-compose there and the command worked.
How do I install docker compose on Alpine Linux?
apk add docker-cli-compose. In the test docker compose version then printed Docker Compose version v5.6.1.
Why does docker compose up -d say unknown shorthand flag instead?
It is the same missing plugin. With a flag after compose, the CLI reported unknown shorthand flag: 'd' in -d and exited with 125.

More decoded errors in the Fixes category. The older hyphenated command is in docker-compose: command not found.