Docker Healthcheck Generator
Build a valid HTTP, TCP or command probe for Docker Compose and Dockerfile.
-
1Enter data
Enter content, paste text or load a file from disk. -
2Click the button
The tool will immediately process your data in the browser. -
3Get the result
Copy the finished text or save the file to your device.
return "Result ready in 0.1s";
}
Rate this tool:
Related tools
Other tools you may find usefulDocker healthcheck generator for Compose and Dockerfile
The Docker healthcheck generator creates two forms of the same probe: a Compose healthcheck block and a Dockerfile HEALTHCHECK instruction. Choose HTTP, TCP or a custom command, set the interval, timeout, retry count and start period, then copy syntax made for the selected format.
A running process does not always mean a working service. A server may stay alive while refusing connections, waiting forever for a database or returning errors. A probe performs a small repeatable check inside the container and lets Docker report a healthy or unhealthy state from its exit code. This tool never contacts a container and never executes the command; it only assembles configuration text.
Which probe type should you choose?
| Type | What it checks | Required in the image | Good fit |
|---|---|---|---|
| HTTP | Status returned by a local URL | curl | API, web application or administration panel |
| TCP | Whether a port accepts a connection | nc | A simple server without a diagnostic endpoint |
| Command | Exit status of your own check | Every program used by the command | Database, queue, worker or project script |
HTTP usually reveals the most, provided that the endpoint checks important dependencies and responds quickly. TCP only proves that something is listening. A custom command is flexible but runs through the container shell, so paste only commands you understand. The generator rejects control characters and line breaks so one value cannot append another Dockerfile instruction.
Timing parameters and the failure threshold
interval controls the delay between checks, timeout limits a single attempt, and retries counts consecutive failures before the state changes. start_period gives the application room to boot; it is not merely a delay before the first check, but a period in which failed attempts do not fill the normal failure counter. The generator accepts clear values using ms, s, m or h, such as 500ms, 30s and 2m.
A sensible baseline for a small API is a 30 second interval, a 5 second timeout, three retries and a 10–30 second start period. Avoid probing every second when the endpoint queries several services. The healthcheck itself can become meaningful load, while ordinary latency spikes turn into false alerts.
How to use the generated result
- Choose HTTP, TCP or a custom command. For HTTP, enter the application port and a path beginning with
/. - Set the timing values and retries. Match the start period to the slowest valid startup rather than the average one.
- Copy the block below
docker-compose.ymlinto the correct service and preserve its YAML indentation level. - If you build an image, copy the instruction below
Dockerfile. Make sure the image actually containscurlornc. - Build the image and inspect the state with
docker inspect. Generated text is not a substitute for testing the real image.
docker inspect --format='{{json .State.Health}}' container-name
docker compose ps
Compose, Dockerfile and the correct CMD syntax
Compose stores a shell command as ["CMD-SHELL", "..."], while a Dockerfile requires HEALTHCHECK ... CMD .... The mechanisms are related, but the word CMD-SHELL is not valid after Dockerfile healthcheck options. The generator keeps these formats separate and encodes the Compose value as a JSON array, so quotes and slashes do not break YAML.
When you are preparing a complete image, use the gitignore generator as a starting list for build-context exclusions and the YAML validator to catch structural mistakes in Compose. A healthcheck belongs to runtime configuration; it does not replace metrics, logs or external monitoring.
Security and failure behavior
A diagnostic endpoint should not reveal versions, configuration, query details or secrets. A plain 200 or 503 is enough. The check runs inside the container, so this generator targets 127.0.0.1 and quotes the URL for the shell. User commands are displayed, not executed by webp.pl.
condition: service_healthy; remediation should be handled by an orchestrator or monitoring system.Do not make a probe depend only on an external website if the container should survive a short DNS outage. Keep passwords and tokens out of commands because image configuration exposes them. Check script permissions with the chmod calculator, and prepare server access rules with the .htaccess generator.
Frequently asked questions
Does Docker restart an unhealthy container automatically?
Not in ordinary Docker Engine operation. Health status is information. The --restart policy reacts to the main process exiting; an orchestrator or an external monitor must be configured to act on an unhealthy state.
Why does curl or nc fail inside my container?
Minimal images often omit these programs. Install the appropriate package while building the image or use a probe based on a runtime already present. Test the program interactively before relying on the healthcheck.
Should the health endpoint check the database?
It depends on intent. A readiness check may include a critical database, while a liveness check should not kill a correct process during a short dependency outage. Docker exposes one healthcheck, so choose a cheap compromise and monitor dependencies separately.
Does a Dockerfile healthcheck work in Kubernetes?
Kubernetes defines its own liveness, readiness and startup probes, so do not assume the image instruction replaces manifest configuration. You can still reuse the same endpoints and commands when writing cluster probes.
How should I choose interval, timeout and retries?
The timeout should exceed a normal response but remain shorter than the interval. Three attempts every 20–30 seconds are a practical baseline for many applications. Tune them later from measured startup time and latency.