One way to achieve this is to wrap the nginx image's entrypoint file in an entrypoint of you own, whose job is to start the cron
service and then hand off to the standard docker-nginx entrypoint. The nginx
image uses the entrypoint /docker-entrypoint.sh
, so we just need to start cron
and pass the command to that script, using an entrypoint like:
#!/bin/bash
cron && /docker-entrypoint.sh "$@"
Here's a simple Dockerfile that creates the necessary entrypoint and overrides the entrypoint in the base image:
FROM nginx
RUN apt-get update && \
apt-get install -y \
cron \
&& \
echo '#!/bin/bash\n\ncron && /docker-entrypoint.sh "$@"' >> entrypoint-wrapper.sh && \
chmod +x /entrypoint-wrapper.sh
ENTRYPOINT ["/entrypoint-wrapper.sh"]
# Have to reset CMD since it gets cleared when we set ENTRYPOINT
CMD ["nginx", "-g", "daemon off;"]
Sample run
$ docker run --name nginx-cron --detach nginx-cron
34301405f7b426022d9c286ff4e00f1c58570d76c5aba6b9f1c50ef698829976
$ docker exec nginx-cron service cron status
cron is running.
$ docker exec nginx-cron service nginx status
nginx is running.