CronNudge

Published October 21, 2026

How to Monitor Cron Jobs Running in Docker

The container is up. docker ps shows it. The crontab is in the image. Nothing runs, and docker logs is empty. Cron in a container fails in ways a host crontab does not: the daemon was never PID 1, the job cannot see the environment Docker injected, and the output was mailed to a sendmail that is not installed.

This page is those failures, the foreground commands that keep the container alive, and a ping so a run that never starts still alerts. A host crontab that does not fire is crontab not running. The heartbeat pattern is how to monitor cron jobs. Two replicas running the same crontab are prevent overlapping cron jobs. A CronJob, which does not need a daemon in the image, is how to monitor Kubernetes CronJobs.

Debian's cron -f and the /etc/cron.d rules below are Debian bookworm cron(8) and crontab(5). BusyBox flags are the ones crond --help prints (-f, -d, -c). Supercronic's environment and logging claims are from its README. The ping URLs are CronNudge's.

The container exits, or cron is not the process

A container stays up while PID 1 stays up. Docker sends signals to PID 1, and docker logs reads PID 1's stdout and stderr. Three ways that goes wrong:

The image's command is your app. Cron was never installed, or it was installed and nothing started it. The app looks healthy. The schedule does not exist. This is the usual base image.

The command is cron or crond without the foreground flag. Debian's cron forks into the background by default, the original process exits, and Docker stops the container because PID 1 exited. BusyBox crond does the same. Its help lists -b as the default. The container lasted a second. There is no log line from a job, because the daemon is already gone.

The entrypoint starts cron in the background and then runs the app. Cron is not PID 1. If the shell then execs the app, cron is reparented and can keep running. If the shell exits, cron dies with it. Either way, job output still does not arrive on the app's stdout unless you redirect it, and a second replica of this pod runs the same crontab again.

Run one process that is the scheduler, in the foreground, and do not also run a web server as PID 1 in that same container unless you have an init that supervises both. The alternatives at the end of this page are the usual way to keep the web process and the schedule apart.

Run the daemon in the foreground

Debian and Ubuntu, package cron, binary cron. cron(8) says -f stays in the foreground and does not daemonize.

FROM debian:bookworm-slim
RUN apt-get update \
 && apt-get install -y --no-install-recommends cron curl ca-certificates tzdata \
 && rm -rf /var/lib/apt/lists/*
COPY job /etc/cron.d/job
RUN chown root:root /etc/cron.d/job \
 && chmod 0644 /etc/cron.d/job \
 && sed -i 's/\r$//' /etc/cron.d/job
CMD ["cron", "-f"]

CMD ["cron", "-f"] does not use a shell. cron -f && something would never reach something, because -f does not return. cron && something, without -f, returns immediately after the fork, something becomes the real work, and the container's lifetime is something's lifetime.

Alpine uses BusyBox crond. -f is the foreground flag. -b is the default, which is the flag that makes the container exit. -d 8 sets the log level and writes the daemon's own messages to stderr, which docker logs can read, when crond --help lists -d. That option is compile-time. If the help has no -d, -L /dev/stderr is the switch the help always lists. -l 8 sets the same level and still logs through syslog (-S is the default), and a slim image has no syslog. -c is the crontab directory. crond --help prints the compiled-in default. Upstream BusyBox uses /var/spool/cron/crontabs. Alpine's own service reads /etc/crontabs/<user>. Pass -c /etc/crontabs when that is the directory you wrote, including when --help shows a different default.

FROM alpine:3.20
RUN apk add --no-cache bash curl tzdata
COPY root /etc/crontabs/root
RUN chmod 0600 /etc/crontabs/root
CMD ["crond", "-f", "-d", "8", "-c", "/etc/crontabs"]

cronie, the daemon on RHEL, Fedora, and Amazon Linux, is a different binary. Its foreground flag is crond -n, not crond -f. -f on cronie is not the BusyBox flag. Read crond --help in the image you are building and use the foreground switch that image's cron actually has.

BusyBox crond also skips a job when it still considers the previous process for that command to be running, and it logs process already running. The command does not start, so it does not ping. That is BusyBox's own overlap rule, not flock, and a skipped minute is invisible unless you are reading crond's stderr (-d). Vixie cron does not do this. It starts the second copy.

-f keeps the container alive. It does not send job output to docker logs. That is a later section. Debian's -L 15 asks cron to log the start, the end, failures, and the pid of each job (the sum of 1, 2, 4, and 8 in cron(8)). Those lines go to the syslog facility cron. Without a syslog daemon they go nowhere. The jobs can still be running. Where those lines land on a host is in where are cron logs.

The job cannot see the container's environment

Docker ENV and docker run -e are in PID 1's environment. Debian cron does not copy that environment into the job. cron(8) is explicit that /etc/environment, when /etc/default/cron points the daemon at it, is read for LANG, LC_ALL, and LC_CTYPE, and that those values set the charset of cron's mail. The same paragraph says this does not affect the environment of tasks running under cron. A printenv dump into /etc/environment does not put DATABASE_URL or CRONNUDGE_URL into the job. It can put secrets into a file that is often world-readable, and it can change the mail charset.

On Debian the variables that do reach the job are the ones cron itself sets (HOME, LOGNAME, SHELL, a short PATH) and the NAME=value lines in the crontab. PATH under cron is often /usr/bin:/bin. A command that works in docker exec because the shell is interactive will not be found from the crontab. Use an absolute path, or set PATH in the crontab file. On a host, that short PATH, a mode 0600 env file, and env > /tmp/cronenv are in cron job environment variables.

BusyBox crond does not wipe the environment. The current source sets HOME, USER, LOGNAME, and SHELL from the passwd entry, and PATH when the crontab contains a PATH= line. Other names already in the crond process, including ones Docker injected, stay. A PATH= line replaces PATH. That is why an Alpine job can see CRONNUDGE_URL without a helper file, and a Debian job cannot.

Write the variables the job needs into a file the job sources. Do that in the entrypoint, when the container starts, so values injected at docker run are included. Limit the names. Prefix each line with export and quote the value with bash's %q, so a child process sees the variable and not only the shell that sourced the file. A naive printenv > file breaks on quotes, spaces, and newlines, and it writes every secret the process can see.

#!/bin/bash
set -euo pipefail
umask 077
: > /run/cron-env.sh
for name in PATH TZ DATABASE_URL CRONNUDGE_URL; do
  if [ -n "${!name+x}" ]; then
    printf 'export %s=%q\n' "$name" "${!name}" >> /run/cron-env.sh
  fi
done
exec cron -f

%q is bash. The shebang has to be bash, not /bin/sh. Debian's /bin/sh is dash, and dash has no %q. /run is the right directory: it is not a layer in the image, and umask 077 keeps the file owner-readable. Do not COPY that file into the image.

Debian /etc/cron.d/job, with the user field. The leading . is the shell's source command. CRONNUDGE_URL in the container environment is visible to the job only because the script sourced the file.

SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

0 3 * * * root . /run/cron-env.sh && /usr/local/bin/job.sh

Alpine's /etc/crontabs/root has no user field. The filename is the user. The same source line otherwise:

SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

0 3 * * * . /run/cron-env.sh && /usr/local/bin/job.sh

Supercronic does not wipe the environment. Its README says jobs inherit the variables set before Supercronic starts, including Docker ENV and docker run -e. You do not need the file for Supercronic, or for BusyBox when the variable is already in the crond process. You do need it for Debian cron. The file is the version that works on both.

Logs that never show up

Debian cron mails job stdout and stderr to the crontab owner. A container has no MTA. It logs No MTA installed, discarding output when syslog is running to hear it. With no syslog, you do not even get that sentence. MAILTO="" in the crontab stops the mail attempt. It does not send the output to stdout. BusyBox mails only when that build includes its sendmail support. Alpine's usual build does not, and crond -f leaves the job attached to the daemon's stdout, so the output can already be in docker logs. The redirect below is what makes Debian and Alpine behave the same way.

Redirect the job at the command. /proc/1/fd/1 is PID 1's stdout, which is what docker logs reads when the scheduler is PID 1. 2>&1 attaches stderr to that same place.

0 3 * * * root . /run/cron-env.sh && /usr/local/bin/job.sh >> /proc/1/fd/1 2>&1

If cron is not PID 1, /proc/1/fd/1 is whatever the main process uses as stdout. That is still the stream docker logs shows, as long as that process kept stdout open. A job that writes only to a file under /var/log is invisible to docker logs until you read the file another way.

% in a crontab line starts a newline. A redirect does not need one. A date +%F on the crontab line does, and it must be written \% or moved into the script. The line has to end in a newline character. Debian's crontab(5) says a last entry that ends at EOF makes cron treat the file as broken, and it writes a warning to syslog.

Timezone

Debian's cron(8) says the daemon uses /etc/timezone when that file is present, and that it runs every task in a single timezone. A TZ= line in the crontab changes the environment of the command. It does not move the minute the daemon fires. That is the same rule as on a Debian host, spelled out in cron jobs and daylight saving time.

ENV TZ=America/New_York without tzdata does not install the zone. The names live in /usr/share/zoneinfo, which the tzdata package provides. Write the name the daemon actually reads, and point localtime at the same file:

RUN printf '%s\n' America/New_York > /etc/timezone \
 && ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime

Alpine's BusyBox crond is not Debian cron. It has no /etc/timezone sentence. The schedule follows the libc zone of the crond process: TZ in that process's environment, or /etc/localtime after tzdata is installed. Set TZ on the container and pass it through, and still install tzdata when the name is not UTC.

Put that same IANA name on the CronNudge check. A container in UTC and a check in America/New_York is an hour off for half the year. The late alert is then the mismatch. UTC schedules do not skip or repeat an hour when a region changes its clocks. The per-daemon fall-back rule is on the daylight-saving page.

The file in /etc/cron.d is ignored

Debian reads /etc/cron.d itself. The files use the system crontab format: five schedule fields, then a user, then the command. A user crontab from crontab -e has no user field. Pasting that file into /etc/cron.d runs the command as a user named after the first word of the command, or it does not run.

cron(8) requires each file to be owned by root, not group-writable, and not world-writable. The executable bit is not required. Mode 0644 and root:root passes. Mode 0666 does not.

The filename has to match run-parts: letters, digits, underscores, and hyphens only. cron(8) says a file in /etc/cron.d cannot contain a dot. job, backup, and nightly-export are read. job.cron, backup.sh, and job.dpkg-new are ignored. The dot rule is why package managers can leave job.dpkg-old beside job without cron running the backup copy.

A CRLF checkout leaves a carriage return on the line. cat -A shows it as ^M. The user field becomes root plus that character, or the command name does, and cron does not find it. sed -i 's/\r$//' in the image build strips it. The last line still needs a newline after the strip.

Alpine's /etc/crontabs/root is a user crontab. There is no user field and no run-parts filename rule, because the file is not in /etc/cron.d. It still needs a trailing newline. The current BusyBox source loads a file only when its name is a user in passwd and the owner is the daemon user, which is root. Mode 0600 matches that. It does not apply Debian's "no dots" rule, and this source does not reject a group-writable file. Pass -c for the directory you wrote.

PID 1, zombies, and stop signals

PID 1 has to reap child processes that exit. A job that double-forks leaves a grandchild. When the intermediate process exits, the grandchild is reparented to PID 1. If PID 1 never calls wait, the grandchild stays as a zombie.

docker run --init puts tini in front of your command. tini reaps zombies and forwards signals. In a Kubernetes pod there is no --init flag of that form. Install tini (package tini on Debian) and make it PID 1:

RUN apt-get update \
 && apt-get install -y --no-install-recommends cron curl ca-certificates tzdata tini \
 && rm -rf /var/lib/apt/lists/*
ENTRYPOINT ["tini", "--"]
CMD ["cron", "-f"]

docker stop sends SIGTERM to PID 1, then SIGKILL after the grace period. tini forwards the signal. A shell script as PID 1 that does not exec and does not trap the signal ignores the stop, and Docker kills it ten seconds later, mid-job.

Supercronic's manual says it reaps zombies when it is PID 1, and -no-reap turns that off when some other init is already PID 1. You do not stack tini and a reaping Supercronic unless you pass -no-reap.

Ways to not run cron in the app container

Supercronic is a crontab runner meant to be PID 1. It stays in the foreground, logs job output and the exit status to stdout and stderr, and does not clear the environment. The crontab is the user form: no user field. Overlap is off unless you pass -overlapping. Pin a release in the image build and check the checksum on that release. Do not copy a checksum out of an old article. The Fly.io setup that uses it is in Render, Railway, and Fly cron.

CMD ["supercronic", "/app/crontab"]

Host cron and docker exec. The daemon stays on the machine, where syslog and a real init already exist. The container has to be running. docker exec uses the environment configured on the container, which is the environment the app already sees.

0 3 * * * docker exec myapp /usr/local/bin/job.sh

If the container is stopped, docker exec fails and nothing pings. That missing ping is the alert you want. This does not survive a host that is rebuilt unless the host crontab is installed there too.

A Kubernetes CronJob creates a Pod on the schedule and tears it down when the container exits. There is no crond to forget. concurrencyPolicy: Forbid skips the new Job while the previous one is still active. startingDeadlineSeconds is how late that occurrence may still start. The manifest and the ping are in the Kubernetes guide.

A scheduler sidecar, or a second process in the same pod, only helps if exactly one copy runs. A Deployment with replicas: 3 and cron in a sidecar starts the job three times. Put the scheduler in its own Deployment with one replica, or use a CronJob. A shared volume does not change that count.

Ping when it finishes

CronNudge has no agent inside the container. The job calls https://cronnudge.com/ping/<check-id> after the work exits 0. GET, POST, and HEAD all count. The response is text/plain ok with Cache-Control: no-store. The ping id is a secret. The badge key is a different id.

curl -fsS fails on HTTP errors and stays quiet unless curl itself fails, so the URL does not land in docker logs. -m 10 caps one transfer at 10 seconds, so a stalled connection cannot hold the container open. --retry 3 retries transient transfer failures. It does not retry "connection refused" unless you also pass --retry-connrefused, which curl has accepted since 7.52.0. -o /dev/null drops the ok body. || true keeps a monitoring failure from becoming the job's exit status. The ping is still missed, and the check alerts after grace.

0 3 * * * root . /run/cron-env.sh && /usr/local/bin/job.sh >> /proc/1/fd/1 2>&1 && curl -fsS -m 10 --retry 3 -o /dev/null "$CRONNUDGE_URL" || true

The && before curl means a failed job.sh does not ping success. The || true at the end also swallows a failed job.sh, which is the wrong exit status if this container's only job is the cron command and you want Docker to show the failure. Split it when you need both the real exit code and a /fail ping:

#!/bin/bash
set -euo pipefail
. /run/cron-env.sh
url="${CRONNUDGE_URL:?CRONNUDGE_URL is not set}"

curl -fsS -m 10 --retry 3 -o /dev/null "$url/start" || true
if /usr/local/bin/job.sh; then
  curl -fsS -m 10 --retry 3 -o /dev/null "$url" || true
else
  status=$?
  curl -fsS -m 10 --retry 3 -o /dev/null "$url/fail?exit=${status}" || true
  exit "$status"
fi

/start records a start and is not a success. /fail marks the check down and alerts immediately when it was not already down. A container that exited before cron started, or a crontab file that cron ignored, never calls either URL. The missing success ping is the backstop.

/start with run tracking on is how a second replica shows up. A second /start while a run is open alerts overlap and does not erase the first run. Without run tracking, that second start does not alert overlap. Max runtime and the reason the loser must not call /fail are in prevent overlapping cron jobs and assertions, runs, and agents. A curl --retry of /start can itself look like a second start if the first request was stored and the response was lost. An Idempotency-Key on that request makes the HTTP retry a replay. Use a different key on the finish ping. The key is per check, not per path.

Default grace is 5 minutes. The form offers none, 1 minute, 5 minutes, 15 minutes, and 1 hour. The API accepts any whole number of seconds from 0 through 7 days. Grace covers lateness of the success ping. A job that runs for 20 minutes does not fit a 5-minute grace if you ping only at the end. Use a grace longer than the run, or ping /start and set Max runtime. With run tracking and no max runtime, an open run is due after the grace period, and that wait is at least 60 seconds, so a long job that pinged /start is marked down while it is still running.

Free is 10 checks, email, and one Slack or Discord channel. The shortest Free interval is 5 minutes, so * * * * * inside the container is not a Free check. Pro is $12 a month for 100 checks, a 1-minute minimum, signed webhooks, and the API. There is no yearly price. Free includes output assertions and run tracking on 3 checks. Pro removes that cap. The numbers are on pricing.

One check per schedule. Compare the five fields on the cron tool in the zone you wrote into /etc/timezone or TZ. The next run should be that zone's clock, not your laptop's.

FAQ

Why does the container exit as soon as cron starts? Debian cron and BusyBox crond fork into the background unless you ask them not to. PID 1 exits, so Docker stops the container. Use cron -f on Debian, crond -f on Alpine, and crond -n on cronie. cron -f does not return, so do not chain another command after it with &&.

Why can the job not see variables that docker exec can see? The interactive shell has the container environment. Debian cron does not pass that environment to the job. /etc/environment is not a substitute: cron(8) says that file, when the daemon reads it, only feeds the mail charset. Source a file the entrypoint wrote, or set NAME=value in the crontab. BusyBox crond does not wipe the environment, so a variable already in the crond process is visible, and a PATH= line in the crontab replaces PATH. Supercronic inherits the container environment and does not need the file.

Where did the job's output go? Debian cron mails it, and a container without an MTA discards it. MAILTO="" stops the mail. It does not attach the output to docker logs. BusyBox mails only if that build has sendmail support. Alpine's usual build does not, so a foreground crond can already show job output. Redirect the command to /proc/1/fd/1 so Debian does too. Daemon log lines from Debian cron go to syslog, which a slim image also does not run.

Does TZ in the crontab change when Debian cron fires? No. TZ= in the crontab is the job's environment. Debian cron(8) schedules in one timezone and uses /etc/timezone when that file is present. Install tzdata, write the zone name there, and set the CronNudge check to the same name. Alpine's crond follows the TZ of the crond process or /etc/localtime.

Why does a file in /etc/cron.d never run? On Debian the name cannot contain a dot, the file must be owned by root and not writable by group or other, and each line needs a user field plus a trailing newline. job.cron is ignored. A CRLF line leaves a carriage return on the user or the command. Alpine does not use /etc/cron.d. Its file is /etc/crontabs/root. Pass -c /etc/crontabs when you start crond yourself. crond --help prints the compiled-in default, which upstream is /var/spool/cron/crontabs and is then not the directory you wrote.

What grace period matches a container cron? Grace is how long after the schedule the success ping may arrive. The default is 5 minutes. A job that runs longer than that, and pings only at the end, needs a longer grace. A job that pings /start needs a max runtime, or the open run is due after grace (at least 60 seconds) and the check goes down while the container is still working.


A container that stays up is not a schedule that fired. The foreground daemon, a job that can see its environment, and a ping after success are three separate checks. Create the check, or read crontab not running for the same failures on a host. Related: overlapping runs and cron expression examples.