Files
projects/Dockers/puppeteer-healthcheck/README.md
T
Bram 0525f42ab8
Build and Push Docker Images / build-and-push (push) Has been cancelled
add some pagination shizzle
2025-07-03 13:20:21 +02:00

4.3 KiB

Puppeteer API Healthcheck

A Docker container that monitors the Puppeteer API and automatically restarts the target container when the API becomes unresponsive.

Features

  • Monitors the Puppeteer API endpoint every minute
  • Automatically restarts the target container after 3 consecutive failures
  • Configurable via environment variables
  • Comprehensive logging
  • Docker socket access for container management
  • Proper Docker permissions handling

Environment Variables

Variable Default Description
BASE_URL https://puppeteer.workwithkora.com Base URL of the Puppeteer API
TEST_URL https://www.google.com URL to test the API with
API_KEY Q7Sd#hhFkyHy*T API key for authentication
TARGET_CONTAINER puppeteer-api Name of the container to restart
CHECK_INTERVAL 60 Health check interval in seconds

Usage

Docker Run

docker run -d \
  --name puppeteer-healthcheck \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -e BASE_URL="https://puppeteer.workwithkora.com" \
  -e TEST_URL="https://www.google.com" \
  -e API_KEY="your-api-key" \
  -e TARGET_CONTAINER="puppeteer-api" \
  -e CHECK_INTERVAL="60" \
  your-registry/puppeteer-healthcheck:latest

Docker Compose

version: "3.8"

services:
  puppeteer-healthcheck:
    build: .
    container_name: puppeteer-healthcheck
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      - BASE_URL=https://puppeteer.workwithkora.com
      - TEST_URL=https://www.google.com
      - API_KEY=your-api-key
      - TARGET_CONTAINER=puppeteer-api
      - CHECK_INTERVAL=60
    restart: unless-stopped
    depends_on:
      - puppeteer-api

How It Works

  1. The healthcheck container makes a GET request to the Puppeteer API every minute
  2. It uses the configured test URL and API key for authentication
  3. If the request fails (non-200 status or timeout), it increments a failure counter
  4. After 3 consecutive failures, it attempts to restart the target container
  5. If the restart is successful, the failure counter is reset
  6. The process continues indefinitely

Logging

The container logs all health check activities to both stdout and a log file (/app/healthcheck.log). Log levels include:

  • INFO: Normal operations and successful health checks
  • WARNING: Failed health checks
  • ERROR: Container restart attempts and failures

Security Considerations

  • The container requires access to the Docker socket to restart other containers
  • Ensure proper API key management
  • The container runs as root for Docker socket access (required for container management)
  • Consider using Docker-in-Docker (DinD) or Docker socket proxy for enhanced security in production

Troubleshooting

Docker Permission Issues

If you see "Permission denied" errors when accessing the Docker socket:

  1. For Docker Run: Add the --group-add flag:

    --group-add $(getent group docker | cut -d: -f3)
    
  2. For Docker Compose: Add the group_add section:

    group_add:
      - docker
    
  3. Alternative: Run the container as root (not recommended for production):

    docker run --user root ...
    

Common Error: "Connection aborted. PermissionError(13, 'Permission denied')"

This error occurs when the container cannot access the Docker socket. To fix:

  1. Mount the Docker socket:

    -v /var/run/docker.sock:/var/run/docker.sock:ro
    
  2. Add the container to the docker group:

    --group-add $(getent group docker | cut -d: -f3)
    
  3. Use the provided docker-compose.yml which includes all necessary configurations.

Container not found

  • Ensure the TARGET_CONTAINER environment variable matches the exact name of your puppeteer-api container
  • Verify the container is running and accessible

API key issues

  • Verify the API key is correct and has the necessary permissions
  • Check that the base URL is accessible from the container

Building

docker build -t puppeteer-healthcheck .

Version

Current version: 1.0.1