Issue
Okay so firstly I read some posts on this topic. That is how I ended up with my solution. Still I don’t find my mistake. Also I am more of a beginner.
FROM conda/miniconda3
WORKDIR /app
RUN apt-get update -y
RUN apt-get install cron -y
RUN apt-get install curl -y
RUN conda update -n base -c defaults conda
RUN conda install mamba -n base -c conda-forge
COPY ./environment.yml ./environment.yml
RUN mamba env create -f environment.yml
# Make RUN commands use the new environment:
SHELL ["conda", "run", "--no-capture-output", "-n", "d2", "/bin/bash", "-c"]
#Setup cron
COPY ./cronjob /etc/cron.d/cronjob
RUN crontab /etc/cron.d/cronjob
RUN chmod 0600 /etc/cron.d/cronjob
RUN touch ./cron.log
COPY ./ ./
RUN ["chmod", "+x", "run.sh"]
ENTRYPOINT ["sh", "run.sh"]
CMD ["cron", "-f"]
What I want to do:
- Run my
run.sh
(I managed to do that.) - Setup a cronjob inside my container which is defined in a file called
cronjob
(see content below)
My cronjob is not working. Why? Note that cron.log is empty. It is never triggered.
Also the output of crontab -l
(run inside of the container) is:
$ crontab -l
# Updates every 15 minutes.
*/15 * * * * /bin/sh /app/cron.sh >> /app/cron.log 2&>1
cronjob
# Updates every 15 minutes.
*/15 * * * * /bin/sh /app/cron.sh >> /app/cron.log 2&>1
Solution
As Saeed said in this comment
First of all, your cronjob command is wrong. You should have
2>&1
instead of2&>1
. Second. runls -lh /app/cron.sh
to see if your file is copied. Also be surecron.sh
is in the directory where yourDockerfile
is.
2&>1
was the mistake that I had made.
Answered By - b3z Answer Checked By - Katrina (WPSolving Volunteer)