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
Copy link
Copy Markdown

@lohitkolluri lohitkolluri commented May 26, 2026

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
Copy link
Copy Markdown

andrebrait commented May 26, 2026

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
Copy link
Copy Markdown
Author

@thaJeztah — when you have a moment, could you please take a review pass on this? Happy to address any feedback.

Thank you.

@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.

Fixes docker#3719

Signed-off-by: Lohit Kolluri <lohitkolluri@gmail.com>
@lohitkolluri lohitkolluri force-pushed the fix/health-cmd-exec-3719 branch from 02221de to 4c9f13d Compare May 26, 2026 14:47
@lohitkolluri
Copy link
Copy Markdown
Author

Hi @thaJeztah, just a gentle follow-up whenever you have a moment.

I’ve addressed the lint issues in the latest commit:

  • shortened the flag description to resolve the revive line-length warning
  • moved the --health-cmd-mode test cases into a separate TestParseHealthCmdMode test to satisfy gocyclo

When convenient, could you please:

  1. Approve the workflow runs for this PR, since the forked workflow executions are currently awaiting maintainer approval
  2. Set the milestone to 29.5.3 so the validate-milestone check can pass. I don’t have the required permissions to assign milestones in this repository.

Please let me know if there’s anything else you’d like me to update or improve. Thanks again for your time and review. I really appreciate it.

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