Reputation: 250
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
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
Reputation: 21
There are two options.
docker container restart CONTAINER_NAME
docker restart CONTAINER_NAME
sudo crontab -e
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
Reputation: 1
Restarting docker requires sudo privileges.I use the following method: sudo crontab -e 00 23 * * * docker restart dbprod
Upvotes: 0