Schedule cron to run R app in Docker in regular intervals

I have an app written in R which scrapes certain data from a website. I want it to run in regular intervals (once a day) in Docker container and scrape the web site automatically.

I am able to run the container with app once. After the app finishes its job, the the container stops. When I log into the container I see that the cron is set, but it does not get chance to start, because container stops after app finishes its scraping.
I run this command to start the container:

docker run -dt my-docker-image-with-app

Here is my simplified Dockerfile:

FROM my-custom-image:latest

# Prepare cron
RUN touch /var/log/cron.log
RUN chmod 0644 /var/log/cron.log

# Copy the app to container
COPY /app /app

# Setup the cron job for my_app.R to run every day at 10:00
RUN (crontab -l ; echo "* 10 * * * Rscript /app/main/my_app.R  >> /var/log/cron.log") | crontab

# Run the command on container startup
CMD cron && tail -f /var/log/cron.log

# Initial start of the app just after the container start
CMD Rscript /app/main/my_app.R

What am I doing wrong please? Many thanks in advance.

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.