0

I am trying to run cron jobs on an alpine-based image (node:18.6.0-alpine3.15 to be exact).

The relevant lines of my Dockerfile are as follows:

FROM node:18.6.0-alpine3.15
RUN apk add--update busybox-suid
COPY ./config/crontab.txt /etc/crontabs/root

When I run this image, cron does not automatically start. If I run crond restart as root in the container, however, it starts running as expected.

I would like to automatically start the cron daemon on startup of the container. What is the recommended way of doing so?

I googled around a bit and found this:

https://wiki.alpinelinux.org/wiki/Alpine_Linux:FAQ#Why_don't_my_cron_jobs_run?

However, this did not solve my issue and cron still did not start up automatically.

1 Answers1

0

There are no background processes in a container, so crond isn't running.

To start it, add

CMD crond -f

at the end of your Dockerfile. That will make crond run in the foreground.

Hans Kilian
  • 18,948
  • 1
  • 26
  • 35
  • I want to run crond in the background, is that possible? I am using the image to run a node.js server, and would like to run that on startup instead. I am also using the "node" user within the image. – Tomas Nyberg Jan 13 '23 at 13:18
  • Just remove the -f – Attila Aug 04 '23 at 15:31