docker - no crontab for root

It's an issue with the dockerfile (rather than the commands in the file). Only one CMD is run (the last one) - see https://docs.docker.com/engine/reference/builder/#cmd

There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect.


As the other answers have already explained, only one CMD will be run per Dockerfile and the command you want to run is wrong.

But there is a more pressing issue with your setup IMO - Docker containers are not usually designed to work this way. What you should do instead is running the cron services from the host (or your orchestrator) as one-off processes (probably using something like docker run or docker-compose run, or, if for some reason you don't want to start a separate container for this, I guess you could use docker exec).

This is just my view on how containers should be used though, so obviously you should take it with a grain of salt.


If you add this to /etc/crontab, this wouldn't show up in root's personal crontab, as this contains only the user-specific crontab edited with crontab -e, not the system-wide one in /etc.


More details:

My guess is that /pulse/crontab.sh (which you don't show, why?) adds the relevant crontab line to the system wide crontab file /etc/crontab. You later execute the command crontab -l, but this only shows an error because it lists roots personal crontab only (which happens to be empty), not the system-wide one in /etc/crontab. This is all perfectly normal and expected. To show the line your script added, you would replace CMD crontab -l with CMD cat /etc/crontab.

All of this has nothing to to with any dockerfile commands like ADD, RUN or CMD, it's just basic Linux stuff.

Tags:

Docker

Cron