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

The following seems to be the equivalent:

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

Where:

  • --no-verbose – Turn off verbose without being completely quiet (use -q for that), which means that error messages and basic information still get printed.
  • --tries=1 – If not set, some wget implementations will retry indefinitely when HTTP 200 response is not returned.
  • --spider – Behave as a Web spider, which means that it will not download the pages, just check that they are there.
  • exit 1 – Ensures exit code 1 on failure. Heathcheck only expects the following:
    • 0: success – the container is healthy and ready for use
    • 1: unhealthy – the container is not working correctly
    • 2: reserved – do not use this exit code

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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)