Skip to content

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).

You can install the Pakyas CLI in your image, or use curl if you prefer no extra binary.

FROM ubuntu:22.04
# Install curl and ca-certificates
RUN 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 script
COPY backup.sh /backup.sh
# Run with monitoring; the public ID is passed at run time
CMD ["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.

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.)

The container itself must be triggered on a schedule. Common approaches:

/etc/cron.d/docker-backup
0 2 * * * root docker run --rm -e PAKYAS_PUBLIC_ID=550e8400-e29b-41d4-a716-446655440000 my-backup-image

Create a timer unit that triggers docker run at the desired interval. See the Linux guide for systemd examples.

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:

/etc/cron.d/db-backup
0 2 * * * root cd /path/to/project && docker compose run --rm db-backup

Ensure you have a .env file locally or secrets in your CI environment:

Terminal window
PAKYAS_API_KEY=pk_live_...