Docker Community Forums

Share and learn in the Docker community.

Docker Swarm - running a cron only in one node


I have a Docker Swarm setup with 4 nodes and I would like to run a cron only in one of these nodes. Is there any elegant solution for this?



Hi :slight_smile:

Just to be sure, you want to deploy a service to 1 node, does it matter which node or just any node?
How do you deploy to the swarm, commandline or docker-compose?


It does’t matter which node. All I want is to make sure my job runs only once at a specific interval (let’s say 24h).
I deploy to the swarm with docker-compose.



you can check this out:
“replicas” in the compose file, defines how many of containers you want to run.

Then you will need a container running cron.

Take a look at swarm-cronjob for this kind of task.

1 Like