DOCKER HEALTHCHECK

The HEALTHCHECK instruction in a Dockerfile is a built-in mechanism to monitor container health. Let me break it down:

What it does:

  1. Defines a health check command that Docker will execute periodically
  2. Reports container health status (starting, healthy, or unhealthy)
  3. Helps detect hung/unresponsive containers even if the process is still running

From your Dockerfile example:

HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health

How it works:

  1. Check Command (curl --fail ...):

  2. Default Timing (if not specified):

Why it's useful for your Streamlit app:

  1. Automatic recovery: Orchestrators (like Docker Compose/Kubernetes) can automatically restart unhealthy containers
  2. Visibility: See container health status in docker ps CONTAINER ID STATUS PORTS NAMES a1b2c3d4e5f6 Up 2 minutes (healthy) 0.0.0.0:8501->8501/tcp pg-viewer
  3. Prevent routing traffic to broken instances in load-balanced setups

How to customize (optional):

HEALTHCHECK --interval=1m --timeout=10s --start-period=30s --retries=3 \
    CMD curl --fail http://localhost:8501/_stcore/health

For your specific use case:

To test health status:

docker inspect --format='{{json .State.Health}}' <container-name>

This helps ensure your database viewer remains operational and automatically flags issues if: - Streamlit process dies but container remains running - Application enters a zombie state - Server becomes unresponsive due to errors