Skip to content

container: add --health-cmd-mode for CMD healthcheck form#7008

Open
lohitkolluri wants to merge 1 commit into
docker:masterfrom
lohitkolluri:fix/health-cmd-exec-3719
Open

container: add --health-cmd-mode for CMD healthcheck form#7008
lohitkolluri wants to merge 1 commit into
docker:masterfrom
lohitkolluri:fix/health-cmd-exec-3719

Conversation

@lohitkolluri

@lohitkolluri lohitkolluri commented May 26, 2026

Copy link
Copy Markdown

docker run/create always wraps --health-cmd in CMD-SHELL, which
fails on scratch and other shell-less images (#3719).

Add --health-cmd-mode with two values:

Value Behavior
shell (default) wraps command in CMD-SHELL — identical to existing behavior
exec uses the exec form (CMD), required for images without a shell

This mirrors the CMD / CMD-SHELL distinction in Dockerfile HEALTHCHECK instructions.

Usage

# exec form for scratch / distroless
docker run --health-cmd=/healthcheck --health-cmd-mode=exec my-image

# multi-argument exec form (parsed with shlex)
docker run --health-cmd='/usr/bin/wget -q -O /dev/null http://localhost/' \
           --health-cmd-mode=exec my-image

# explicit shell form — same as omitting --health-cmd-mode
docker run --health-cmd='curl -f http://localhost/' --health-cmd-mode=shell my-image

Test plan

  • go test ./cli/command/container/... -run TestParseHealth
  • make mddocs (docs regenerated in this commit)

Fixes #3719

@andrebrait

Copy link
Copy Markdown

How about an option --health-cmd-mode with values shell (the default) and exec?

Just in case the future has even more modes possible, so changing this is easier?

@andrebrait

andrebrait commented May 26, 2026

Copy link
Copy Markdown

Or cmd instead of exec, or upper-case, etc.

Up to the maintainers to know what they prefer, but I'm just throwing the idea out there.

@lohitkolluri lohitkolluri force-pushed the fix/health-cmd-exec-3719 branch from e09b71d to ec531ea Compare May 26, 2026 12:15
@lohitkolluri lohitkolluri changed the title container: add --health-cmd-exec for CMD healthcheck form container: add --health-cmd-mode for CMD healthcheck form May 26, 2026
@lohitkolluri

Copy link
Copy Markdown
Author

@andrebrait Great suggestion — updated to --health-cmd-mode with string values shell (default, keeps CMD-SHELL behavior) and exec (uses the CMD form). This is cleaner and leaves room for future modes.

Changes in the latest commit:

  • --health-cmd-exec bool--health-cmd-mode string (default "shell")
  • Error on unrecognised mode value
  • Tests updated for both modes + invalid-mode case
  • Docs regenerated via make mddocs

@lohitkolluri lohitkolluri force-pushed the fix/health-cmd-exec-3719 branch from ec531ea to 02221de Compare May 26, 2026 13:59
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

docker run/create always wrapped --health-cmd in CMD-SHELL, which fails
on scratch and other shell-less images. Add --health-cmd-mode=exec to
produce the exec (CMD) form, matching Dockerfile HEALTHCHECK CMD
behavior. The default "shell" preserves existing --health-cmd behavior
unchanged.

Signed-off-by: Lohit Kolluri <lohitkolluri@gmail.com>
@lohitkolluri lohitkolluri force-pushed the fix/health-cmd-exec-3719 branch from 4c9f13d to 426b622 Compare June 10, 2026 11:00
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.

Image from "scratch" has no shell, but passing the --health-cmd to docker run uses CMD-SHELL

4 participants