Health Checks & Restart Policies

HEALTHCHECK

HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
  CMD curl -fsS http://localhost:8000/health || exit 1

Example (status)

docker ps --format "table {{.Names}}\t{{.Status}}"

Example output

NAMES   STATUS
api     Up 2 minutes (healthy)

Restart Policies

PolicyRestarts the container...
no (default)never
on-failure[:5]when it exits with an error (max 5 times)
unless-stoppedalways, unless you stopped it manually
alwaysalways, also after the Docker daemon restarts
docker run -d --restart unless-stopped myapi:1.0