title: Cron isn't running when I start my docker container
body: <p>To preface, I have been referencing these two articles for help:</p>
  
  <ul>
  <li><a href="https://www.ekito.fr/people/run-a-cron-job-with-docker/" rel="noreferrer">Run a cron job with Docker - Julien Boulay</a></li>
  <li><a href="http://www.anotherchris.net/posts/running-cron-jobs-inside-a-docker-container" rel="noreferrer">Running cron jobs inside a Docker container - Chris S.</a></li>
  </ul>
  
  <p>My goal is to have a cron job automatically start when I start my docker container. Currently, it doesn't automatically start, but I can manually go into my container and run <code>service cron start</code>, which starts the job, and it works correctly.</p>
  
  <p>So the problem is: <strong>How do I get my cron job to start automatically when my container starts up?</strong></p>
  
  <p><em>Dockerfile</em></p>
  
  <pre><code>FROM microsoft/dotnet:latest
  RUN apt-get update &amp;&amp; apt-get install -y cron
  
  COPY . /app
  
  WORKDIR /app
  
  ADD crontab /etc/cron.d/crontab
  RUN chmod 0600 /etc/cron.d/crontab
  RUN crontab -u root /etc/cron.d/crontab
  RUN touch /var/log/cron.log
  
  RUN ["dotnet", "restore"]
  
  RUN ["dotnet", "build"]
  
  EXPOSE 5000/tcp
  
  CMD cron &amp;&amp; tail -f /var/log/cron.log
  CMD service cron start
  </code></pre>
  
  <p><em>crontab</em></p>
  
  <pre><code>* * * * * echo "Hello world" &gt;&gt; /var/log/cron.log 2&gt;&amp;1
  # Empty space
  </code></pre>
  
  <hr>
  
  <p>Though I wasn't able to get cron working in that particular container, I was able to create a standalone docker container specifically for cron, and was successful in getting it to run automatically.</p>
  
  <p>As far as setup for the cron container, I followed the linked article, <a href="https://www.ekito.fr/people/run-a-cron-job-with-docker/" rel="noreferrer">Run a cron job with Docker - Julien Boulay</a>, and was able to get it working.</p>