Docker Community Forums

Share and learn in the Docker community.

Docker Swarm - running a cron only in one node

swarm

(Tibi21) #1

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


(Martin Terp) #2

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?


(Tibi21) #3

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


(Martin Terp) #4

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.