I have a critical container application which task consist of polling sensors and taking consequent action on some external hardware.

If the application of the container crashes it's fine. restart: always will take care of this.

However if the application hangs, possibly blocked on IO or another unexpected event, this is where things can go wrong as the external hardware will get stuck in it's state possibly indefinitely.

I'd like my container application to periodically communicate with something and if it stops doing so, the container gets restarted.

Does this kind of mechanism exists?

I'm running the container with Docker.

  • Are you considering to run a CaaS like k8s as well? If the container is run in k8s then one could define a liveness check. If it fails then k8s will restart the container.
    – 030
    Aug 29 at 12:04

Create health endpoint inside application and call it from outside and if no response restart docker


by using docker stack you can achieve a health check. you can add the below lines in docker-compose.yaml.

version: '3.1'

    image: docker-flask
      - '5000:5000'
      test: curl --fail -s http://localhost:5000/ || exit 1
      interval: 1m30s
      timeout: 10s
      retries: 3

Reference: https://howchoo.com/devops/how-to-add-a-health-check-to-your-docker-container

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.