Edit 2023-07-17
There is now support implemented for setting a start-interval
to check in a shorter interval during the start-period
The feature is expected to be released in version 25 of the docker engine.
Example:
HEALTHCHECK --interval=5m --start-period=3m --start-interval=10s \
CMD curl -f http://localhost/ || exit 1
In this example, there is a start-interval
of 10s, which means the first healthcheck is done 10s after the container has been started. After that, the healthcheck is repeated every 10s, until either the health state switches to healthy
, or the start-period
is over (3m). After that, it proceeds the healthchecks at the regular interval
(5m).
Docker Docs: https://docs.docker.com/engine/reference/builder/#healthcheck
Related pull request: https://github.com/moby/moby/pull/40894
Original Answer as of 2021
There is currently no built in way to decrease the time, until the first healthcheck is performed. Docker always waits a full interval between the container start and the first healthcheck. The start-period
option just defines a grace time, that allow healthchecks to fail without marking the container as unhealthy. This will only be meaningful, if the interval
is lower than the start-period
.
There is a feature request to add an option, that decreases the interval while the container is starting, to get the container faster into a healthy state:
https://github.com/moby/moby/issues/33410