0

I try to put a script that sends me a mail, in the crontab of my container (node:18-alpine3.15).

Here are my scripts:

--- Dockerfile

FROM node:18-alpine3.15

COPY node/index.js /home
COPY node/.env /home
COPY node/entrypoint.sh /home

WORKDIR /home

RUN chmod +x /home/entrypoint.sh;apk add --update npm;npm install dotenv;npm install nodemailer;npm install @notionhq/client; /home/entrypoint.sh
ENTRYPOINT ["tail", "-f", "/dev/null"]

---entrypoint.sh

#!/bin/ash

echo "* * * * * cd /home && node index.js" >> /etc/crontabs/root
crond -l 2 -f > /dev/stdout 2> /dev/stderr &
echo "Starting" > /Starting

After starting the container, the directory /Starting exists (so the script was executed).

Also when I display the crontab :

# cat etc/crontabs/root 
# do daily/weekly/monthly maintenance
# min hour day month weekday command
*/15 * * * * run-parts /etc/periodic/15min
0 * * * * run-parts /etc/periodic/hourly
0 2 * * * run-parts /etc/periodic/daily
0 3 * * 6 run-parts /etc/periodic/weekly
0 5 1 * * run-parts /etc/periodic/monthly

* * * * * cd /home && node index.js

So my modifications were done, but I don't receive any mail.

But if I decide to run the script by hand :

/home/entrypoint.sh

it works and I get the mail.

Do you have an idea to fix this behavior?

Ztn_mine
  • 9
  • 1
  • 3
  • You've set the container's `ENTRYPOINT` to a no-op "keep the container alive" `tail` process. The container will never do anything at all unless you use manual debugging tools like `docker exec`. Do you mean to remove this `ENTRYPOINT` line, and set the image's `CMD` to something else (maybe your `entrypoint.sh` script)? – David Maze Oct 11 '22 at 10:18
  • Here is described how to deal with cron in docker: https://stackoverflow.com/questions/37458287/how-to-run-a-cron-job-inside-a-docker-container – Slava Kuravsky Oct 11 '22 at 10:44

0 Answers0