Docker & Docker Compose
This guide covers monitoring scheduled batch jobs that run in containers (backups, ETL, cleanup tasks). For the container to be monitored correctly, it must be scheduled externally (cron, systemd timer, or orchestrator).
Dockerfile
Section titled “Dockerfile”You can install the Pakyas CLI in your image, or use curl if you prefer no extra binary.
Option A: Install CLI (Recommended)
Section titled “Option A: Install CLI (Recommended)”FROM ubuntu:22.04
# Install curl and ca-certificatesRUN apt-get update && apt-get install -y --no-install-recommends curl ca-certificates \ && rm -rf /var/lib/apt/lists/*
# Install Pakyas to /usr/local/bin (the default is ~/.local/bin)RUN curl -fsSL https://pakyas.com/install.sh | PAKYAS_INSTALL_DIR=/usr/local/bin sh
# Copy scriptCOPY backup.sh /backup.sh
# Run with monitoring; the public ID is passed at run timeCMD ["sh", "-c", "exec pakyas monitor --public-id \"$PAKYAS_PUBLIC_ID\" -- /backup.sh"]Pin a version for reproducible builds with PAKYAS_VERSION=0.1.9 next to PAKYAS_INSTALL_DIR.
To ping by slug instead, use CMD ["pakyas", "monitor", "docker-backup", "--", "/backup.sh"] and pass PAKYAS_API_KEY to the container.
Option B: Use Curl
Section titled “Option B: Use Curl”CMD curl -fsS https://ping.pakyas.com/$PAKYAS_PUBLIC_ID/start && \ /backup.sh && \ curl -fsS https://ping.pakyas.com/$PAKYAS_PUBLIC_ID(Note: Option B reports nothing when /backup.sh fails, so a failure only shows up later as a missed ping, and no exit code or error output is sent.)
Scheduling the Container
Section titled “Scheduling the Container”The container itself must be triggered on a schedule. Common approaches:
Using cron
Section titled “Using cron”0 2 * * * root docker run --rm -e PAKYAS_PUBLIC_ID=550e8400-e29b-41d4-a716-446655440000 my-backup-imageUsing systemd timer
Section titled “Using systemd timer”Create a timer unit that triggers docker run at the desired interval.
See the Linux guide for systemd examples.
Docker Compose
Section titled “Docker Compose”Pass the API key (or the check’s public ID) as an environment variable.
services: db-backup: build: . environment: - PAKYAS_API_KEY=${PAKYAS_API_KEY} entrypoint: ["pakyas", "monitor", "db-backup", "--", "./backup.sh"]With only PAKYAS_API_KEY set, the CLI looks up the key’s organization and the check by slug. Each new container starts with an empty slug cache, so every run makes these lookups; --public-id avoids them.
Run the service on a schedule using cron or a scheduler:
0 2 * * * root cd /path/to/project && docker compose run --rm db-backupEnsure you have a .env file locally or secrets in your CI environment:
PAKYAS_API_KEY=pk_live_...