cron and crontab are missing in docker image of ubuntu 16.04

Solution 1:

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

Need to run apt-get install cron

Solution 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.