Debugging

Cron not running in Docker.

Installing cron in an image isn't enough. A container doesn't start services, cron jobs don't inherit the container's environment, and job output doesn't reach docker logs. Fix all three.

1. Nothing starts the cron daemon

A container runs one main process, whatever CMD or ENTRYPOINT says. There's no init system, so systemctl enable cron does nothing (and usually fails with "System has not been booted with systemd"). Run cron in the foreground as the main process:

# Debian / Ubuntu base
FROM debian:13-slim
RUN apt-get update && apt-get install -y --no-install-recommends cron \
    && rm -rf /var/lib/apt/lists/*
COPY mycron /etc/cron.d/mycron
RUN chmod 0644 /etc/cron.d/mycron
CMD ["cron", "-f"]
# Alpine base — BusyBox crond is already there
FROM alpine:3
COPY mycron /etc/crontabs/root
CMD ["crond", "-f", "-l", "2"]

Files in /etc/cron.d/ need a username field (* * * * * root /app/job.sh). Alpine's /etc/crontabs/root doesn't, and copying over it replaces the image's default root crontab. Both need a newline after the last line.

Docker's own guidance is one service per container. If cron has to share a container with your app, use a small wrapper script or a process manager such as supervisord as the main process, and run the container with --init so finished job processes get cleaned up.

2. Jobs don't see your environment variables

Variables you pass with -e or env_file belong to the container's main process. Cron starts jobs with a fresh, minimal environment: on Debian, SHELL=/bin/sh and PATH=/usr/bin:/bin unless the crontab sets them. So DATABASE_URL is empty and anything in /usr/local/bin is "not found".

Two ways round it:

# a) set what you need at the top of the cron file
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
* * * * * root /app/job.sh
# b) save the runtime environment at start-up and load it in the job
# entrypoint.sh
export -p > /etc/job.env      # POSIX: prints quoted, re-loadable lines
chmod 600 /etc/job.env
exec cron -f

# cron line
* * * * * root . /etc/job.env; /app/job.sh

Option (b) writes every variable, including secrets, to a file inside the container. Keep it chmod 600, or write only the variables the job needs.

3. Output doesn't appear in docker logs

docker logs shows the main process's stdout and stderr. Cron jobs are children whose output cron tries to email. Redirect each job to the main process's output streams:

* * * * * root /app/job.sh > /proc/1/fd/1 2> /proc/1/fd/2

This works for jobs that run as root (only root can write to PID 1's streams). Without a redirect, Debian cron logs No MTA installed, discarding output and the output is gone.

4. The time zone is UTC

Most base images run in UTC, so 0 9 * * * fires at 09:00 UTC. Set TZ and install time zone data if you need local time:

ENV TZ=Asia/Kolkata
RUN apt-get install -y tzdata     # Alpine: apk add tzdata

See cron time zone handling.

On Kubernetes, don't put cron in the container

Use a Kubernetes CronJob resource instead: each run gets its own pod, logs and retry policy. Our Kubernetes CronJob generator writes the YAML.

Check the whole file at once. Paste or upload your crontab into the crontab checker. It reads the file the way Debian/Ubuntu cron, cronie or BusyBox does, lists every error instead of stopping at the first, and also flags lines that install fine but run wrongly (on Alpine, day-of-week 7 runs every day and a # anywhere cuts the command short).

Sources

Checked against these official sources and, where marked, tested on Ubuntu 24.04 (cron 3.0pl1-184ubuntu2). Last verified 18 November 2026.