HEALTHCHECK in the Dockerfile rather than the compose file

A healthcheck describes how to tell whether this particular software is working, which is knowledge that belongs with the image rather than with each stack that uses it.

HEALTHCHECK --interval=10s --timeout=3s --start-period=30s --retries=3 
  CMD php-fpm-healthcheck || exit 1

# and for something without a purpose-built checker:
HEALTHCHECK CMD curl -fsS http://localhost/health || exit 1

--start-period is the flag that stops a slow boot being reported as a failure, and it was added in 17.05 — without it a database that takes forty seconds to initialise looks unhealthy during every normal start. The check runs inside the container, so it needs whatever it calls to be installed, and adding curl purely for a healthcheck is a common and slightly annoying reason for an image to grow. A compose-level healthcheck overrides the image’s, which is useful for a stack that needs a stricter one.