Menu

How to run a cron job in a Docker container (with logs)
πŸ“°

How to run a cron job in a Docker container (with logs)

DEV Community: dockerΒ·octave NkurunzizaΒ·8 days ago
#RqoL40mD
#devtodocker#devto#dev#cron#docker
Reading 0:00
15s threshold

Last updated: 5 November 2026 Β· Applies to Debian-based images (python:3.13-slim, Debian 13 trixie) with Debian cron 3.0pl1, Alpine 3.24, supercronic 0.2.51, Docker Compose v2+

You want a script to run every night, or every five minutes, next to your app in Docker. This guide shows how to run a cron job in a Docker container so that it actually fires, sees the same environment variables as your app, prints to docker logs , never runs twice at once, and stops cleanly on docker stop .

Why it matters: cron inside a container fails silently. No error, no log line, the job just never runs, and you find out a week later when the backups are missing. Many popular guides stop at CMD cron && tail -f , which hides exactly the problems that bite in production.

Try it on Hubfly space : deploy the Compose file below as a two-container stack.

Run a cron job in a Docker container: the short answer

Run cron as its own service built from the same image as your app.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.