cron not working in a docker container on NAS synology

115 Views Asked by At

I've created a Docker image that includes a cron job, but the cron job is not executing as expected. I'm encountering the following error: "/etc/cron.d/cronjob: 4: Dockerfile: not found".

Here are the relevant files in my project:

Dockerfile:

FROM node:latest

WORKDIR /app

RUN apt-get update && apt-get install -y cron

#COPY package.json package-lock.json ./
#RUN npm install

COPY . .

RUN chmod +x script.js

RUN touch /var/log/cron.log

COPY cronjob /etc/cron.d/cronjob

RUN chmod 0644 /etc/cron.d/cronjob

COPY entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh

CMD ["/usr/local/bin/entrypoint.sh"]

EntryPoint.sh

#!/bin/bash

set -x

cron -f &

sleep 10

cd /var/log && tail -f cron.log

cronjob:

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

* * * * * echo "Hello from cron" >> /var/log/cron.log 2>&1
#commented lines to exec script.js, but i'm trying easy command first

I'm trying to execute a cron job every minute within my Docker container, with the simple command of echoing a message. However, an unusual error is preventing the execution, specifically stating "/etc/cron.d/cronjob: 4: Dockerfile: not found".

I would appreciate any assistance or insights on how to resolve this issue. My expectation is to see the "Hello from cron" message printed to the log every minute.

Thank you in advance for your help!

0

There are 0 best solutions below