Menu

Cron in Docker FAQ: 11 questions from everyone whose job worked locally and does nothing in the container
📰

Cron in Docker FAQ: 11 questions from everyone whose job worked locally and does nothing in the container

DEV Community: docker·delay.run·3 days ago
#3qSg2wGU
#devtodocker#devto#dev#cron#container
Reading 0:00
15s threshold

Putting a cron job in a Docker container looks like a five-minute task. Install cron, copy a crontab, start the daemon. Then the job silently doesn't run, or runs without its environment, or runs at the wrong hour, and there's no output anywhere.

Here are the questions that come up most, with direct answers.

1. Should I run cron inside a container at all?

Sometimes. The container philosophy is "one process per container", and cron is a long-running daemon that spawns other processes, which fits awkwardly. Common alternatives:

Host cron calling docker run or docker exec .

Your orchestrator's scheduler : Kubernetes CronJobs, ECS scheduled tasks, Nomad periodic jobs, a PaaS scheduler.

A container-friendly scheduler such as supercronic (a crontab-compatible runner designed for containers) or ofelia (a scheduler for Docker that runs jobs in other containers).

That said, a small "cron container" running alongside your app is a perfectly reasonable choice for a single server with Docker Compose.…

Continue reading — create a free account

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