Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

7
  • 1
    Note: it's a fairly common recommendation to run cron jobs on the docker host instead of inside each container. I prefer not to do that, I prefer containers to be entirely self-contained and not require any special configuration on the host. IMO requiring special per-container configuration defeats a large part of the automation and ephemeral re-usability benefits provided by containerising tasks. Commented Mar 9, 2018 at 2:49
  • I have already done apt-get install cron. I'm using FROM nginx:stable... When I exec in my container and do service cron start it works perfectly. But I need the cron service to start automatically when the container is created. But it does not work Commented Mar 9, 2018 at 10:02
  • what's nginx:stable based on? where did it come from? github.com/nginxinc/docker-nginx ? (there are alpine and debian stretch based versions there). somewhere else? Commented Mar 9, 2018 at 15:21
  • It's the official stable version of nginx on docker hub, github.com/nginxinc/docker-nginx/blob/… . Commented Mar 9, 2018 at 19:19
  • OK, according to the Dockerfile, that's based on Debian stretch. It already has CMD ["nginx", "-g", "daemon off;"] and I can't recall if you can run multiple commands with CMD or not. Maybe try something like CMD ["cron;", "nginx", "-g", "daemon off;"]. If that doesn't work, create a script that runs cron and then nginx -g daemon off, COPY it to your container, RUN chmod +x path/to/your/script, and add CMD /path/to/your/script. Commented Mar 10, 2018 at 1:43