3

This is my Dockerfile

FROM ubuntu:16.04
RUN apt-get update -y && apt-get install -y \
  git \
  python \
  python-pip

After the docker image is created, I login and try to setup a cron job for testing. To my surprise, cron and crontab are not present.

# ls 
app  bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  
root  run  sbin  srv  sys  tmp  usr  var
# crontab -l
/bin/sh: 6: crontab: not found
# crontab -l
/bin/sh: 7: crontab: not found
# crontab -l
/bin/sh: 10: crontab: not found
# cron
/bin/sh: 11: cron: not found

But I expect cron to be present in an ubuntu image. Did I pick a wrong image or is there anything I need to do to enable cron?

  • Just install it? – Gerald Schneider Jun 1 '17 at 8:37
  • Do a which crontab command also you could move to other shell as like as bash if it is installed and try with bash completion – Ali Mezgani Jun 1 '17 at 8:37
  • Else yoi should pick another image or build a private one for your future usage – Ali Mezgani Jun 1 '17 at 8:39
  • @MezganiAli which crontab confirms it is not installed. I think I will install it. I did not encounter this problem when install ubuntu normally on VM or real PC. So not sure why it is missing – Anthony Kong Jun 1 '17 at 8:43
6

The cron command is not installed by default in the image ubuntu:16.04

Need to run apt-get install cron

2

Docker images are minimal by design, and they are used for creating containers, not a full operating system. A container is isolating the running of an application, so it will not have all the other OS daemons running inside that environment like cron, syslog, mail etc, by default.

You can install cron with:

RUN apt-get update \
 && DEBIAN_FRONTEND=noninteractive apt-get install \
      cron \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/*

inside your Dockerfile. However to run the crontab entries, you also need to start the cron daemon as part of your container startup process. There are tools like forego and supervisord that you can use to run multiple processes in your container (cron plus your app), but doing so is often the sign of an anti-pattern.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.