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
?
The cron command is not installed by default in the image ubuntu:16.04
Need to run
apt-get install cron
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:
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.