Each RUN
command creates a temporary container on your build host using the resulting image from the prior step and the RUN
arg as the container's command. A container only runs as long as the command you execute is active, so if it's a command that launches a background daemon like you've done, the container exits when the command returns, not when the background daemon exits.
The RUN
command is used to build up your image which is the layered filesystem and various meta data that tells docker how to use that filesystem (environment variables, entrypoint and/or command to run by default, etc). It is very different from a CMD
which tells docker what to run when that image is turned into a container. So for a process that you need to have running in the container, that needs to be part of your CMD
or ENTRYPOINT
since running processes from RUN
are not part of a static filesystem image.
I'd also follow the advice of others and copy an already existing image with cron inside, no need to reinvent this wheel. You may want to use a tool like supervisord to run cron and your application together if you need to have multiple processes inside your container. Though when possible, you should work out how to break this into multiple containers that can be independently updated.