dockerwget

How can I make a Docker healthcheck with wget instead of curl?


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.

This is because the docker image has wget installed and I don't want to have to install curl.


Solution

  • The following seems to be the equivalent:

    HEALTHCHECK  --interval=5m --timeout=3s \
      CMD wget --no-verbose --tries=1 --spider http://localhost/ || exit 1
    

    Where:

    Docker compose example:

    healthcheck:
       test: wget --no-verbose --tries=1 --spider http://localhost || exit 1
       interval: 5m
       timeout: 3s
       retries: 3
       start_period: 2m
    

    https://docs.docker.com/compose/compose-file/compose-file-v3/#healthcheck