Dockerfile Cheat Sheet/Add health check

Define a health check command for the container.

Section: Common Patterns

Add health check

dockerfile
dockerfile
HEALTHCHECK --interval=30s --timeout=5s --retries=3 CMD wget -qO- http://localhost:3000/health || exit 1
Explanation

Useful with orchestrators and compose health status.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Common Patterns
Use multi-stage build
Build artifacts in one stage and copy only runtime output into the final stage.
OpenIn sheetdockerfilesame section
Run as non-root
Switch the runtime user away from root.
OpenIn sheetdockerfilesame section
Cache dependencies effectively
Copy dependency manifests before application code to maximize layer cache reuse.
OpenIn sheetdockerfilesame section
Use .dockerignore
Exclude unnecessary files from build context.
OpenIn sheetgitignoresame section
Copy with ownership
Copy files with explicit ownership.
OpenIn sheetdockerfilesame section
Build from Dockerfile
Build an image from the Dockerfile in the current directory.
OpenIn sheetbash1 tag match