user3472897
user3472897

Reputation: 250

Crontab won't restart Docker container

I have a container that runs under a Root account which I can start using:

docker start containername

and I want crontab to start it, so as root I used

crontab -e

and set an entry like this:

* * * * * /usr/bin/docker start containername

but it won't work. I also tried

* * * * * root /usr/bin/docker start containername

with no luck.

Anyone has a clue on how I can make this work?

Upvotes: 7

Views: 16542

Answers (3)

Benyamin Jafari
Benyamin Jafari

Reputation: 34046

I did it without any problems as follows:

$ crontab -e

then I set a restart for a container every 5 minutes:

*/5 * * * * docker restart <containername>

Upvotes: 5

Luis Hern&#225;ndez
Luis Hern&#225;ndez

Reputation: 21

There are two options.

docker container restart CONTAINER_NAME

docker restart CONTAINER_NAME
  1. sudo crontab -e
  2. 0 1 * * * docker container restart CONTAINER_NAME

You can see with the next command:

sudo crontab -l

Test with Docker version 19.03.6, build 369ce74a3c

Upvotes: 1

Rafal Lysik
Rafal Lysik

Reputation: 1

Restarting docker requires sudo privileges.I use the following method: sudo crontab -e 00 23 * * * docker restart dbprod

Upvotes: 0

Related Questions