Docker container healthcheck stop unhealthy container Docker container healthcheck stop unhealthy container docker docker

Docker container healthcheck stop unhealthy container


Try Changing from kill to exit 1

HEALTHCHECK --start-period=30s --timeout=5s --interval=1m --retries=2 \CMD bash /expressvpn/healthcheck.sh || exit 1

Reference from docker docs

Edit 1:

After some testing if you want to kill the container on unhealthy status you need to do it in the health check script /expressvpn/healthcheck.sh or by script on the host.

The following example the container status is healthy:

HEALTHCHECK --start-period=30s --timeout=5s --interval=10s --retries=2 CMD bash -c 'echo "0" || kill 1' || exit 1

The following example the container stops since the command ech not exit then the kill 1 is executed and the container got killed:

HEALTHCHECK --start-period=30s --timeout=5s --interval=10s --retries=2 CMD bash -c 'ech "0" || kill 1' || exit 1

Edit 2:

Well after a bit of digging i understood something that i saw in some dockerfiles:

RUN apt update -y && apt install tini -yENTRYPOINT ["tini", "--"]CMD ["./echo.sh"]

From what i got docker keeps the pid 1=entrypoint process from getting killed by SIGTERM so for this you have tini small util that helps with this (still not sure what exactly the purpose of this i will keep it for next time i will be in the mood..).
Anyway after adding tini the container got killed with kill 1

Thank you for the question.


please check the output of your health check. You'll have to ensure that your healthcheck actually fails 2 consecutive times.

docker inspect  --format "{{json .State.Health }}" <container name> | jq