• Hello Guest! SynoForum.com is celebrating its 5th anniversary! 🥳🎉 Read more...

ubuntu docker: cron not working!

Currently reading
ubuntu docker: cron not working!


I try to setup a scheduled task within my Ubuntu container, not working at all:

- crontab -e
* * * * * root env > /tmp/env.output

  • Yes! cron service start I can see it using top or pgrep cron, time& date is correct same as host.
  • I checked all this Q&A at askubuntu, not working;
  • under /etc, 5 folders can be found : i.e. cron.d/; cron.daily/; cron.hourly/; cron.monthly/; cron.weekly; and a file crontab
what else shoud l check and debug?

thanks in advance for any hints
Last edited:
thanks for help.

I have installed Utuntu standard from Synology Docker lineup, after that (apt-get) installed some required packages (e.g. cron), please let me where to find compose.yml or how to generate?
Last edited:
Ah, you just pulled the image and did things manually.

Typicaly an os run in a docker container is merly a bunch of loose binaries and config files, that - due to the absense of systemd (or any other supervisor daemons) - do nothing by their own. The behavior of the os in a container is not even remotely close to the behavior of the same os on bare metal or in a vm.

Commands are rarely executed directly in the shell of a docker container. Instead people write Dockerfiles to perform a scripted (as in automated) setup of the main application and its dependencies, along with one or more clever entrypoint scripts that use environment-variables or mounted files to generate the runtime configuration before the main application is started.

Here is a simple example how such a Dockerfile could look like: Ekito/docker-cron
This one has no clever entrypoint, though...
not working, even very simple test file, e.g.
* * * * * touch /tmp/cronworks
Never seen any file generated.

I think you are right spot-on that Docker's container(e.g. ubuntu) as discrete LEGO system(image) missing integrity/completeness of the functionalities,hence the lean & base system is only to work for certain task-oriented script, once the tasks are too versatile, it will miss dependencies or framework and not function. Thus it is the user's responsibility to add or tailor-making for the designated job.

cron in docker container of ubuntu is hereby a typical example:
- the initial Ubuntu container not incl. cron even;
- ubuntu has only one user, i.e. root, which confuses cron additionally;
- No syslog or cron.log to debug or to trace,

even I tried to instal: apt-get -y install rsyslog
it throws me warnings:
... invoke-rc.d: could not determine current runlevel invoke-rc.d: policy-rc.d denied execution of start.
also need to know how to restart cron service automatically if ubutu container reboot.
Didn't the example for Github work for you?

The solution is quite straight forward:

The example crontab file:
* * * * * root echo "Hello world" >> /var/log/cron.log 2>&1
# Don't remove the empty line at the end of this file. It is required to run the cron job

Add the local file 'crontab' into the container and make it executable:
# Add crontab file in the cron directory
ADD crontab /etc/cron.d/hello-cron

# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/hello-cron

Precondition for CMD :
# Create the log file to be able to run tail
RUN touch /var/log/cron.log

Start chron on container start and tail the logfile to STDOUT:
# Run the command on container startup
CMD cron && tail -f /var/log/cron.log
you mean to solve the cron issue, I have to build my own new container/image using the Dockerfile?

Could we avoid re-inventing the wheel? :)
even though I generated the Dockerfile and creating a new one, still not through:
$ sudo docker - < Dockerfile Sending build context to Docker daemon 2.048kB Step 1/8 : FROM ubuntu:latest ---> 7698f282e524 Step 2/8 : MAINTAINER [EMAIL][email protected][/EMAIL] ---> Running in 8ec7076a835d Removing intermediate container 8ec7076a835d ---> e54192f946cd Step 3/8 : ADD crontab /etc/cron.d/hello-cron ADD failed: stat /volume1/@docker/tmp/docker-builder744673875/crontab: no such file or directory
The ADD declaration is used to copy files from the host into the container.
I assume you didn't take a look at the git repo. You need to create a file called crontab and paste the content I provided earlier.

Pls. correct me if mistaken:
I have to 1:1 copied the content of Ekito/docker-cron to Dockerfile;
The dockerfile is to generate a new container/image in SynoNAS.
the build failed, e.g. ADD crontab /etc/cron.d/hello-cron
But SynoNAS/DSM has no crontab, on the other side, the container has not been built, thus also cannot add that file.

Referring to the error log above:
ADD failed: stat /volume1/@docker/tmp/docker-builder744673875/crontab: no such file or directory
you may know /volume1/@docker is not accessible...
Still frustrated and don't know why my via crontab -e setup-ed schedule in ubuntu container not working and no syslog coming out.
I guess the problem is:

invoke-rc.d: could not determine current runlevel
invoke-rc.d: policy-rc.d denied execution of start.

strangely I noticed if ubuntu is in bridge mode than OK in host is NOK.
It is not only the Dockerfile which is required, the additional file called "crontab" from the repository is also required and needs to be in the same folder.

You observation with the network mode is odd, it shouldn't affect the chron binary at all.
Thanks for your persistent standby helping. But I am afraid we are still not touching the root cause.

Currently I am studying the systemd for ubuntu 18.04, which should be start-up in my docker image/container. But Synology/DSM has not make it possible, instead I can use service. i.e.
root@ubuntu:/# systemctl status System has not been booted with systemd as init system (PID 1). Can't operate.

But sudo service --status-all shows:
[-] cron
i.e. cron not started.

This goes to the root of Synology/DSM configuration, how its embeded Docker container starts/boots -up.


Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Similar threads

I can’t find any option to restore just the settings. 1710356648 Phew, managed to fix it. Within the...
Good to hear. Deluge has not been updated for almost two years now as an app, nevertheless. But it gives...
  • Question
Open an issue on that GitHub page. The developers will be glad to assist. OP has posted two threads on...
I'm happy with email notifications but in v0.3.3 of dockcheck the author added apprise notifications...
I am also trying to setup a Z-wave USB dongle and am getting stuck after following the same steps as...
How did you create the Portainer container in first place? As in exact docker run commands or in case...
Looks like I triggered you somehow with my post: it was not my intention. I have no idea whether bash or...

Welcome to SynoForum.com!

SynoForum.com is an unofficial Synology forum for NAS owners and enthusiasts.

Registration is free, easy and fast!