-1
Dockerfileを使用して2分ごとに "hello world"を印刷するcronジョブを作成したいとします。 私はDockerのウェブサイトからubuntuイメージを使用しています。新しいコンテナ、Dockerfileとcrontabファイルを作成しました。ドッカー・コンテナ内のDockerfileを使用したcronジョブの作成
crontabファイル:
* * * * * root echo "Hello world" >> /var/log/cron.log 2>&1
//空行が有効なのcronファイルについては、このファイルの末尾に必要です。ここに私のファイルの内容です。
Dockerfile
FROM ubuntu:latest
MAINTAINER [email protected]
// Add crontab file in the cron directory
ADD crontab /etc/crontab/hello-cron
// Give execution rights on the cron job
RUN chmod 0644 /etc/crontab/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 /etc/crontab/hello-cron && tail -f /var/log/cron.log
私は私のドッキングウィンドウの画像とコンテナをビルドして実行するには、これらのコマンドを入力:
sudo docker build --rm -t cron/cron-example .
sudo docker run -t -i ekito/cron-example
私が実行した後にこのメッセージを受け取っ:
/bin/sh: 1: /etc/crontab/hello-cron: Permission denied
でホストサーバでのcronを追加を実行するためのドッキングウィンドウでのcron、クーロン自体がありますデーモンであり、crontabファイルを直接実行するべきではありません。実行可能ビットもcronファイルではオンにならず、ファイルを実行可能にする必要があるのではなく 'RUN chmod 0755/etc/crontab/hello-cron' – bjhaid