Skip to content

container/ps: add HealthCheck formatter field#6913

Open
Mohammed-Thaha wants to merge 1 commit intodocker:masterfrom
Mohammed-Thaha:6203-add-healthcheck-format
Open

container/ps: add HealthCheck formatter field#6913
Mohammed-Thaha wants to merge 1 commit intodocker:masterfrom
Mohammed-Thaha:6203-add-healthcheck-format

Conversation

@Mohammed-Thaha
Copy link
Copy Markdown

- What I did

Added a new docker ps --format placeholder: .HealthCheck, so users can print container health state directly as a dedicated field.

Fixes #6203.

- How I did it

  • Added HealthCheck() to the container formatter context.
  • Returned health directly from c.c.Health.Status when available.
  • Added fallback parsing from .Status text for:
    • (healthy) -> healthy
    • (unhealthy) -> unhealthy
    • (health: starting) -> starting
  • Updated docs in docs/reference/commandline/container_ls.md to include .HealthCheck in the format placeholders table.
  • Added/updated unit tests in cli/command/formatter/container_test.go.

- How to verify it

  1. Start dev shell:

    make -f docker.Makefile shell
  2. Build the CLI binary:

    make binary
  3. Run a container that stays in starting during the start period:

    docker rm -f hc-starting 2>/dev/null || true
    
    ./build/docker-linux-amd64 run -d --name hc-starting \
      --health-cmd='exit 1' \
      --health-start-period=2m \
      --health-interval=5s \
      --health-retries=1 \
      alpine sh -c 'sleep 300'
  4. Verify formatter output:

    ./build/docker-linux-amd64 ps -a --filter name=hc-starting --format "table {{.Names}}\t{{.Status}}\t{{.HealthCheck}}"

Expected result:

  • STATUS contains (health: starting)
  • HEALTHCHECK shows starting

- Human readable description for the release notes

`docker ps --format` now supports a `.HealthCheck` placeholder to print container health state (`starting`, `healthy`, `unhealthy`) as a dedicated field.

- A picture of a cute animal (not mandatory but encouraged)

Signed-off-by: Mohammed Thaha <mohammedthahacse@gmail.com>
@Mohammed-Thaha Mohammed-Thaha requested review from a team and thaJeztah as code owners April 5, 2026 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

update docs, tests, local changes for "HealthCheck" in "ps" response

1 participant