CRON in Docker


Helmonder

7 posts in this topic Last Reply

Recommended Posts

How do i enable a crontab job in a docker ?

 

I need to have my spotweb docker refresh every hour.. I can give the command manually from console..

 

In a VM I can do this , I can also do it in unraid itself, setting it up in the GO file, but I am unsure how to do this in a docker and having it survive a reboot.

Link to post
7 hours ago, Helmonder said:

I can give the command manually from console

 

7 hours ago, Helmonder said:

I can also do it in unraid itself, setting it up in the GO file

Probably the best option, or via user scripts.  Any changes (adding a cronjob) within the image will get lost if/when the container gets updated

Link to post
21 hours ago, Helmonder said:

But how though.. I can set a cron job to run through the go file for unraids own environment, but how do i do it for the environment of a docker ?

you would set up your script to be something like

docker exec -t NameOfContainer CommandToRun

 

Link to post

Thanks... Have to do a bit more digging... In my spotweb container there is no CRON present.. So I would have to make a script executed via the GO as follows:

 

apt-get update
apt-get -y install cron

 

Then something that puts the following line in cron from commandline:

 

@hourly /usr/bin/php /var/www/spotweb/spotweb/retrieve.php

 

Then I would have to make sure that the docker is running when the GO file is executed.. Possibly work with a pause in there..

 

Link to post
  • 1 year later...

i have spotweb running in the "nginx" docker with the database on the "mariadb" docker. The "nginx" docker has cron buildin

 

Addad the following user script on unraid: Download "CA User Scripts" from CA. Go to Settings --> User Scripts --> ADD NEW SCRIPT. add a script name for example "update spotweb" click on the newly created user script named: update sportweb (blue text) and click "Edit Script" remove all text and paste this:

 

#!/bin/bash
docker exec -t nginx php /config/www/spotweb/retrieve.php > /dev/null

 

afbeelding.png.ac5bfae1ceb49b5cf7b0a47f8ac05ff2.png

/config/www/spotweb/retrieve.php is the path to the retrieve.php file from within the docker container.

 

Click SAVE CHANGES and set Schedule Disabled to Scheduled hourly

afbeelding.thumb.png.f05bc24ec88cb9daa1810011d53f1372.png

 

If you do this the script "update spotweb" (the cronjob) survives an update of the "nginx" docker.

 

Out of curiosity in what docker are you running spotweb ?

 

 

Edited by Dikkekop
Link to post
  • 3 weeks later...

That post was a blast from the past.. Things have been running for over a year.

 

At the moment I am using jgeusebroek/spotweb for spotweb. I was using the MySQL docker as a datebase but at some point it failed and I switched to the Postgres11 docker (postgres:11) which now works fine.

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.