Skip to content

[BUG] docker compose ps --status behavior differs from documentation #11464

Description

@adam-hintz-olo

Description

When looking for exited containers by status, containers do not show up unless I also pass the --all flag.

$ docker compose ps --status=exited | wc -l
1

$ docker compose ps --all --status=exited | wc -l
7

This is in conflict with what I see in the docs:

docker compose ps --status=exited
NAME            IMAGE     COMMAND           SERVICE    CREATED         STATUS          PORTS
example-bar-1   alpine    "/entrypoint.�"   bar        4 seconds ago   exited (0)

Steps To Reproduce

Given the following docker-compose.yml:

version: "3"
services:
  ls:
    image: alpine:latest
    command: "ls"

Run the following commands and observe the output:

$ docker-compose up -d
## output truncated

$ docker compose ps
NAME      IMAGE     COMMAND   SERVICE   CREATED   STATUS    PORTS

$ docker compose ps --all
NAME                   IMAGE           COMMAND   SERVICE   CREATED          STATUS                      PORTS
docker-ps-repro-ls-1   ubuntu:latest   "ls"      ls        15 seconds ago   Exited (0) 13 seconds ago

$ docker compose ps --status=exited
NAME      IMAGE     COMMAND   SERVICE   CREATED   STATUS    PORTS

$ docker compose ps --status=exited --all
NAME                   IMAGE           COMMAND   SERVICE   CREATED          STATUS                      PORTS
docker-ps-repro-ls-1   ubuntu:latest   "ls"      ls        36 seconds ago   Exited (0) 34 seconds ago

Compose Version

Docker Compose version v2.24.3-desktop.1

Docker Environment

Client:
 Version:    25.0.2
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.12.1-desktop.4
    Path:     /usr/local/lib/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.24.3-desktop.1
    Path:     /usr/local/lib/docker/cli-plugins/docker-compose
  debug: Get a shell into any image or container. (Docker Inc.)
    Version:  0.0.22
    Path:     /usr/local/lib/docker/cli-plugins/docker-debug
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.0
    Path:     /usr/local/lib/docker/cli-plugins/docker-dev
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.21
    Path:     /usr/local/lib/docker/cli-plugins/docker-extension
  feedback: Provide feedback, right in your terminal! (Docker Inc.)
    Version:  v1.0.4
    Path:     /usr/local/lib/docker/cli-plugins/docker-feedback
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v1.0.0
    Path:     /usr/local/lib/docker/cli-plugins/docker-init
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     /usr/local/lib/docker/cli-plugins/docker-sbom
  scout: Docker Scout (Docker Inc.)
    Version:  v1.3.0
    Path:     /usr/local/lib/docker/cli-plugins/docker-scout
WARNING: Plugin "/usr/local/lib/docker/cli-plugins/docker-scan" is not valid: failed to fetch metadata: fork/exec /usr/local/lib/docker/cli-plugins/docker-scan: no such file or directory

Server:
 Containers: 28
  Running: 20
  Paused: 0
  Stopped: 8
 Images: 98
 Server Version: 25.0.2
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  seccomp
   Profile: unconfined
  cgroupns
 Kernel Version: 5.15.133.1-microsoft-standard-WSL2
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 32
 Total Memory: 31.3GiB
 Name: docker-desktop
 ID: 1fdd7e93-a030-4ecb-bc9d-463f4b845867
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: daemon is not using the default seccomp profile

Anything else?

Tested in WSL (Ubuntu 20.04.6 LTS) and PowerShell on the same machine (Windows 11).

Activity

  1. adam-hintz-olo commented on Feb 5, 2024

    @adam-hintz-olo
    Author

    Note: docker compose ps --filter status=exited gives the same behavior as docker compose ps --status=exited
    E: All of this filter behavior differs from docker ps, which works as docker compose ps is described in the docs

  2. 1arp commented on Feb 8, 2024

    @1arp
    Contributor

    I have created a pull request to resolve this issue in the code. I am not sure if this is an issue in the code or the documentation.

  3. 1arp commented on Feb 8, 2024

    @1arp
    Contributor

    I was able to trace it down to the compose ComposeService using the docker command.Cli.Client().ContainerList() which by default uses shows the running option unless --all is provided.

    The service gets the containers using the above mentioned client and adds a filter to it leading it only apply filter to the running containers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions