How to do 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

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

Tags:

Docker

Wget