speed up docker healthcheck containers

Viewed 553

I'd like to speed up the container startup time but my healthcheck is not allowing me. Let's say I'm having this healthcheck

HEALTHCHECK --interval=300s --timeout=5s --start-period=5s --retries=3 CMD \
    curl http://localhost:<port> > /dev/null || exit 1

What I want is to not wait 300+ seconds to start the container but check if it is healthy after e.g. 10s [maybe the app inside it is up and running after 10 seconds] and if everything is ok to start the container.

I need the interval to be 300+ seconds as I don't want to check the internal health of it more often than 1/300

How can I achieve that?

1 Answers

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

Related