Docker Community Forums

Share and learn in the Docker community.

Docker Swarm - running a cron only in one node

Hi,

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?

Thanks,

Tiberiu

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?

Hello,

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.

Thanks,

Tiberiu

you can check this out: https://docs.docker.com/compose/compose-file/#replicas
“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