2

So I have this Dockerfile:

From ubuntu:16.04
RUN apt-get update && apt-get -y install cron sudo watch vim
RUN useradd --create-home --shell /bin/bash mark
RUN mkdir /joel  
COPY ./crontab_delete /joel 
WORKDIR /joel
RUN ls -al 
RUN cron -f 
RUN crontab myCrontab

I then do docker exec --user mark -it CONTAINER_NAME bash and I can see that the cron is running but I then need to execute crontab myCrontab which works from being inside the container via docker exec... but if you put it as the last command since I need to start the cron in foreground BEFORE running my crontab file the docker build... hangs at RUN cron -f and doesn't allow the last command to run

UPDATES

The linked post no longer work as of 2018; maybe someone has an updated Dockerfile they could share ? The above Dockerfile doesn't start the cronjob for me but when I do ps -aux | grep cron I can see that the cron service is running

pelican
  • 5,846
  • 9
  • 43
  • 67
  • Possible duplicate of [How to run a cron job inside a docker container?](https://stackoverflow.com/questions/37458287/how-to-run-a-cron-job-inside-a-docker-container) – David Maze Jul 26 '18 at 19:39
  • https://stackoverflow.com/questions/37461868/whats-the-difference-between-run-and-cmd-in-a-docker-file-and-when-should-i-use Is also relevant. The short answer is, you can’t really start daemons in a Dockerfile like this. – David Maze Jul 26 '18 at 19:41
  • Does anyone have a working dockerfile that I could referenced? The linked post doesn't work anymore and that post is addressing system crons but I need user crons which require running crontab myCrontab AFTER running crontab -f in foreground but doing so doesn't work for me. Please see my updates in question above – pelican Jul 26 '18 at 19:52
  • The author of that answer `(VonC)` on the linked duplicate post says that it also no works and used to work at the time: `https://stackoverflow.com/questions/37458287/how-to-run-a-cron-job-inside-a-docker-container#comment84170990_37458519` – pelican Jul 26 '18 at 20:00

0 Answers0