derM
derM

Reputation: 13691

docker-compose healthcheck and depends_on service_healthy is super slow

This is my mvp docker-compose.yml:

version: '2.4'

services:
  first:
    image: alpine:latest
    entrypoint: sleep 100s
    healthcheck:
      test: sleep 1
      timeout: 2s
      start_period: 1s


  second:
    image: alpine:latest
    entrypoint: sleep 10s
    depends_on:
      first:
        condition: service_healthy

What I'd expect to happen:

  1. start service first (might take a few seconds)
  2. a second after the start, the test sleep 1 should return, turning the service healthy
  3. starting service second (might take a few seconds)
  4. service second terminates after 10 more seconds

However what happens:

  1. start service first (takes a few seconds)
  2. nothing happens for some 30 seconds
  3. start service second
  4. service second terminates after 10 more seconds

Where is my misconception that explains this huge difference?

(I don't want a discussion, on weather having healthchecks and depends_on conditions are good practice ore not. That would not be on topic for this question)

Upvotes: 3

Views: 3398

Answers (1)

derM
derM

Reputation: 13691

The misconception is:

The default value for the parameter interval is 30s. And though the parameter start_period might suggest something different, the first health check is performed after that interval.

The start_period does not demark the time, the healthchecks start but instead the time, negative results would be considered not fatal.

Therefore it is impossible to define a sensible waiting time for the first health_check without providing unsensible intervals, the check is rerun during the whole life time.

Upvotes: 4

Related Questions