Monitor Cron Jobs Inside Docker Containers

DevOps & CI/CD

The Problem

Running cron inside Docker containers is tricky. Cron doesn't inherit environment variables, PID 1 issues cause zombie processes, and container restarts reset the cron daemon.

The Solution

Use a proper init system (tini) or supervisord in your container, and add CronRabbit monitoring for external job verification.

Docker Cron Challenges

Docker containers need special handling for cron: environment variables aren't passed to cron, the cron daemon needs to be PID 1 (or managed by init), and container logs need proper forwarding.

Recommended Pattern

Use your application's built-in scheduler when possible. If you must use system cron, use tini as the init process and export env vars to cron.

Code Examples

Dockerfile with cron and monitoring

Bash
FROM python:3.12-slim
RUN apt-get update && apt-get install -y cron curl tini

COPY crontab /etc/cron.d/myapp
RUN chmod 0644 /etc/cron.d/myapp && crontab /etc/cron.d/myapp

ENTRYPOINT ["tini", "--"]
CMD ["cron", "-f"]

crontab file with monitoring

Bash
# /etc/cron.d/myapp
0 2 * * * root /app/backup.sh && curl -fsS -m 10 --retry 5 --retry-all-errors https://ping.cronrabbit.com/your-id >> /proc/1/fd/1 2>&1

Ready to Monitor Your Cron Jobs?

Create your free account and add your first monitor in under 5 minutes. No credit card required.