Created
April 7, 2018 07:06
-
-
Save Natata/ff83c0b5a348b02884ede5162ae90e1d to your computer and use it in GitHub Desktop.
Dockerfile example for run cron job on ubuntu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ubuntu:16.04 | |
MAINTAINER natataworld@love.com | |
ARG USER=docker_user | |
RUN apt-get update && apt-get -y install cron sudo | |
# create a normal user | |
RUN adduser --disabled-password --gecos '' $USER | |
RUN adduser $USER sudo | |
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers | |
USER $USER | |
# Add crontab file in the cron directory | |
ADD crontab /home/$USER/hello-cron | |
RUN sudo chown $USER:$USER /home/$USER/hello-cron | |
# Give execution rights on the cron job | |
RUN chmod 0644 /home/$USER/hello-cron | |
# Create the log file to be able to run tail | |
RUN touch /home/$USER/cron.log | |
# Run the command on container startup | |
RUN crontab /home/$USER/hello-cron | |
CMD sudo service cron start && /bin/bash | |
# How to use: | |
# # docker build --rm -t natata/cron-example . | |
# # docker run -it natata/cron-example:latest | |
# in the container: | |
# # tail -f /home/docker_user/cron.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment