Skip to content
StackDecode
IntermediateLesson 16 of 26

Healthchecks, restart policies and limits

Make containers recover, and stop them hogging the machine.

dockerfile
HEALTHCHECK --interval=30s --timeout=3s CMD curl -f http://localhost:8000/health || exit 1
bash
docker run -d --restart unless-stopped myapp
docker run -d --memory 512m --cpus 1.5 myapp
docker stats                      # live CPU and memory

Restart policies: no (default), on-failure, always, unless-stopped. A container killed for exceeding its memory limit shows OOMKilled in docker inspect.