Hi I'm trying to run a cron job in a docker container.
So I have added that in my
FROM nginx:stable RUN apt-get update -y && apt-get upgrade -y && apt-get install -y \ vim \ git \ curl \ wget \ certbot \ cron COPY cron/crontab /etc/crontab RUN chmod 0644 /etc/cron.d/crontab RUN /etc/init.d/cron start
# /etc/crontab: system-wide crontab # Unlike any other crontab you don't have to run the `crontab' # command to install the new version when you edit this file # and files in /etc/cron.d. These files also have username fields, # that none of the other crontabs do. SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # m h dom mon dow user command */1 * * * * root echo "test" >>~/readme
But it does not work.
I have to run the command
/etc/init.d/cron start manually in my nginx container if I want it to work.
So I have added an entrypoint in my
Dockerfile, so this command can be executed when the container start.
# ENTRYPOINT ADD entrypoint.sh /entrypoint.sh RUN chmod 777 /entrypoint.sh
#!/usr/bin/env bash /etc/init.d/cron start
But I have this error:
OCI runtime exec failed: exec failed: container_linux.go:296: starting container process caused "process_linux.go:86: executing setns process caused \"exit status 21\"": unknown
Did I miss something?
PS: I have followed this tutorial