Docker healthcheck document shows this for curl:
HEALTHCHECK --interval=5m --timeout=3s \
CMD curl -f http://localhost/ || exit 1
I want a one-line equivalent in wget that would exit 1 when HTTP 200 is not returned.
We can also see the health status by running docker ps. Notice under STATUS, the status is Up with (healthy) next to it. The health status appears only when a health check is configured.
If a health check fails but the subsequent one passes, the container will not transition to unhealthy . It will become unhealthy after three consecutive failed checks. --timeout – Set the timeout for health check commands. Docker will treat the check as failed if the command doesn't exit within this time frame.
Docker Swarm is a clustering and scheduling tool for Docker containers. With Swarm, IT administrators and developers can establish and manage a cluster of Docker nodes as a single virtual system. Swarm mode also exists natively for Docker Engine, the layer between the OS and container images.
2. Docker Compose depends_on. depends_on is a Docker Compose keyword to set the order in which services must start and stop. For example, suppose we want our web application, which we'll build as a web-app image, to start after our Postgres container.
The following seems to be the equivalent:
HEALTHCHECK --interval=5m --timeout=3s \
CMD wget --no-verbose --tries=1 --spider http://localhost/ || exit 1
Dennis Hoer's answer is great, but I prefer -nv
(--no-verbose
) instead of --quiet
, then if an error occurs, the reason is available from Docker:
HEALTHCHECK --interval=5s --timeout=5s --retries=3 \
CMD wget -nv -t1 --spider 'http://localhost:8000/' || exit 1
Example output captured by Docker:
% docker inspect $container --format "{{ (index (.State.Health.Log) 0).Output }}"
Connecting to localhost:8000 (127.0.0.1:8000)
wget: server returned error: HTTP/1.1 404 Not Found
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With