DevOps

[Docker] Crontab 설치

nineDeveloper 2020. 9. 3.
728x90

https://codeday.me/ko/qa/20190325/152387.html

Cron Job

* * * * * root echo "Hello world" >> /var/log/cron.log 2>&1

Dockerfile

FROM ubuntu:latest
MAINTAINER docker@ekito.fr

RUN apt-get update && apt-get -y install cron

# Add crontab file in the cron directory
ADD crontab /etc/cron.d/hello-cron

# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/hello-cron

# Create the log file to be able to run tail
RUN touch /var/log/cron.log

# Run the command on container startup
CMD cron && tail -f /var/log/cron.log

Build & Excute

sudo docker build --rm -t ekito/cron-example .
sudo docker run -t -i ekito/cron-example

Result

Hello world
Hello world
728x90

댓글

💲 추천 글