Docker compose keeps running healthcheck

Question:

I am running a couple of services with docker compose.

The data-loader service has to wait for the translator, but once the data-loader is running, the healthcheck does not stop executing, even after exiting.

translator:
build: ./translator
container_name: translator
command: uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
healthcheck:
  test: curl -f translator:8000/healthcheck || exit 1
  interval: 5s
  timeout: 5s
  retries: 5
env_file:
  - ./translator/.env
networks:
  - fds-network
ports:
  - 8000:8000
restart: always
depends_on:
  - redis
volumes:
  - ./translator:/app/

data-loader:
build:
  context: ./data-loader
  dockerfile: Dockerfile
container_name: data-loader
command: python3 app/main.py
environment:
  - "DOCKER=true"
  - "BASE_LANG=es"
  - "LOAD_DISEASES=false"
depends_on:
  cassandra-load-keyspace:
    condition: service_completed_successfully
  translator:
    condition: service_healthy
env_file:
  - ./data-loader/.env
networks:
  - fds-network

The endpoint for the healthcheck:

@app.get("/healthcheck")
async def healthcheck():
    return {"status": "ok"}

And this is the console output:

cassandra-load-keyspace exited with code 0
data-loader              | Dataloader connected to Cassandra
data-loader              | Dataloader started
data-loader              | load diseases False
data-loader              | Skipping disease loading
translator               | INFO:     172.18.0.4:46638 - "GET /healthcheck HTTP/1.1" 200 OK
data-loader exited with code 0
translator               | INFO:     172.18.0.4:56822 - "GET /healthcheck HTTP/1.1" 200 OK
translator               | INFO:     172.18.0.4:56836 - "GET /healthcheck HTTP/1.1" 200 OK
translator               | INFO:     172.18.0.4:40618 - "GET /healthcheck HTTP/1.1" 200 OK
translator               | INFO:     172.18.0.4:40624 - "GET /healthcheck HTTP/1.1" 200 OK
translator               | INFO:     172.18.0.4:51620 - "GET /healthcheck HTTP/1.1" 200 OK
translator               | INFO:     172.18.0.4:51630 - "GET /healthcheck HTTP/1.1" 200 OK

and so on.

If the data-loader service is running it is because the healthcheck was OK, and the number of calls to the endpoint is greater to the number of tries in the condition for the healthcheck, and no more services nor functions call that endpoint, so it must be the healthechk at the compose.

What is wrong here?

Asked By: Francisco Aguilera

||

Answers:

so it must be the healthechk at the compose.

Yes, translator health check is run by docker, which will keep running the health check every 5 seconds interval: 5s, whether there are any dependent services running or not.

Answered By: s3vt
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.