docker / docker/cli

docker ps -f should return nonzero exit status for no matches

Open
#6,640 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

kind/feature status/0-triage
Dominant language
Go
Stars
6.1k
Forks
2.2k
Avg merge
1d 15h
Merged PRs (30d)
43

Description

Description

As per vdemeester comment, re-opening https://github.com/moby/moby/issues/35057.

Reason to close was command will return zero even when "docker ps" returns no containers.

If instead docker ps returns ie 1 or not zero when container is not running, it then enables better integration with other tooling:

# Conventional Exit Code Use - ls command on folder exists, not-exists
 
if [[ $( ls /tmp 2>/dev/null ) ]]; then echo "folder exists"; else echo "folder does not exist"; fi

folder exists
 
if [[ $( ls /tmpXX 2>/dev/null ) ]]; then echo "folder exists"; else echo "folder does not exist"; fi

folder does not exist

# Docker ps - Less Useful Zero Exit Code

if [[ $( docker ps --filter label=runningimage=no 2>/dev/null ) ]]; then echo "container is running"; else echo "container is not running"; fi

container is running

??? WHY
 
eg, docker ps - no containers are running
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
.... 


Another closer example, "pgrep" - listing processes by process matching, clearly explains rationale:

...
       -c, --count
              Suppress  normal  output;  instead print a count of matching processes.  When count does not match anything, e.g. returns zero, the command will return
              non-zero value. Note that for pkill and pidwait, the count is the number of matching processes, not the processes that were  successfully  signaled  or
              waited for.


Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the docker ps command and its filter handling, then trace how an empty result currently determines the process exit status. The change is done when docker ps -f returns a nonzero status for no matching containers while retaining the expected output and integration behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.