1

I want to schedule a monthly restart of a docker container that has been set up with docker stack deploy.

$ docker stack ls
NAME           SERVICES   ORCHESTRATOR
hello-docker   1          Swarm

But there seems to be no docker stack restart <name> command. So how could I tell docker to force a restart on a specific stack?

Or if not possible, restarting the whole docker daemon would also be fine from cron.

Update The scale option in the linked question is a nice trick:

docker service scale myservice=0
docker service scale myservice=1
membersound
  • 81,582
  • 193
  • 585
  • 1,120
  • Do you mean the cron linux feature or some docker feature like cron? – JRichardsz Apr 11 '22 at 14:15
  • I mean from a `crontab` job on the host system (ubuntu). – membersound Apr 11 '22 at 14:17
  • I think, on an external manager system you would use a tool like ansible: `ansible swarm -m systemd -a "name=docker state=restarted` – Chris Becke Apr 11 '22 at 14:26
  • `Or if not possible, restarting the whole docker daemon` → [`sudo systemctl restart docker`](https://docs.docker.com/config/daemon/systemd/) – rzlvmp Apr 11 '22 at 14:59
  • crontab is so easy. Do you need to execute any shell command (docker in your case) at regular intervals on the same machine? – JRichardsz Apr 11 '22 at 18:09
  • @rzlvmp but that does not work from within `crontab`! – membersound Apr 12 '22 at 07:08
  • @JRichardsz yes I want to restart the daemon or a single container on a regular basis each month. – membersound Apr 12 '22 at 07:08
  • check this to understand how cron works https://www.guru99.com/crontab-in-linux-with-examples.html Basically you can execute any shell sentence at any day or interval. In your case could be: 0 0 1 * * docker service update --force 3xrdy2c7pfm3 – JRichardsz Apr 12 '22 at 14:16

0 Answers0