cronping

Docker Compose

Monitor containerized cron jobs and scheduled tasks with Cronping.

Cronping works with any container that can make outbound HTTPS requests. Add a ping command after the scheduled task completes.

One-off job service

services:
  backup:
    image: postgres:16
    environment:
      DATABASE_URL: ${DATABASE_URL}
      CRONPING_URL: ${CRONPING_URL}
    volumes:
      - ./backups:/backup
    command:
      - /bin/sh
      - -c
      - |
        pg_dump "$$DATABASE_URL" | gzip > /backup/db.sql.gz
        curl -fsS --retry 3 --max-time 10 "$$CRONPING_URL/$$?"

Run it from your host scheduler:

0 2 * * * docker compose run --rm backup

With Ofelia

Ofelia runs Docker jobs on a cron schedule.

services:
  backup:
    image: postgres:16
    environment:
      DATABASE_URL: ${DATABASE_URL}
      CRONPING_URL: ${CRONPING_URL}
    command:
      - /bin/sh
      - -c
      - |
        pg_dump "$$DATABASE_URL" | gzip > /backup/db.sql.gz
        curl -fsS --retry 3 --max-time 10 "$$CRONPING_URL/$$?"
    volumes:
      - ./backups:/backup
    labels:
      ofelia.enabled: "true"
      ofelia.job-run.backup.schedule: "0 2 * * *"
      ofelia.job-run.backup.container: "backup"

  ofelia:
    image: mcuadros/ofelia:latest
    command: daemon --docker
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro

Capture output

services:
  etl:
    image: myapp:latest
    environment:
      CRONPING_URL: ${CRONPING_URL}
    command:
      - /bin/sh
      - -c
      - |
        ./etl.sh > /tmp/etl.log 2>&1
        EXIT_CODE=$$?
        curl -fsS --retry 3 --max-time 10 \
          -X POST "$$CRONPING_URL/$$EXIT_CODE" \
          -H "Content-Type: text/plain" \
          --data-binary @/tmp/etl.log
        exit $$EXIT_CODE

In Compose files, use $$ when you want the variable expanded inside the container instead of by Docker Compose on the host.

On this page