Search code examples
dockerdocker-composehealth-monitoringhealth-check

If a container exits within docker compose, does it take its healthcheck with it?


If I specify a service within a docker-compose.yaml file and that service (container) exits, does the healthcheck go down with it?

I assume the answer is no and that docker compose is smart enough to continue checking on it, but I can't seem to find any documentation online to answer this specific question.

Example service configuration:

app:  # this service exits
  image: my_cool_app:v1.2.3
  healthcheck:  # does this keep running at the given interval?
    test: ["CMD", "curl", "-f", "https://my_server.com/cool/app/", "||", "exit", "1"]
    interval: 1m
    timeout: 10s
    retries: 3
    start_period: 1m

Solution

  • The healthcheck is implemented by an exec into the running container. When the container exits or is otherwise stopped, all exec'd processes are also stopped and no further healthchecks will run. As Turing85 mentions in the comments, there's nothing to check, the container isn't unhealthy, it's down.