LoginSignup
38
31

More than 5 years have passed since last update.

alpine linuxでcron用コンテナを作る

Posted at

やりたいこと

alpine linuxでcron用のコンテナを作りたい

環境

  • docker 1.10.2
  • Alpine linux 3.3.1

やり方

  • /var/spool/cron/crontabs/rootにcronの設定を書き込む
* * * * * echo "Hello"
  • crondをフォアグラウンドで起動
crond -l 2 -f

以上。

  • ワンライナーで実行したり
$ docker run -it alpine sh -c "echo '* * * * * echo foobar' > /var/spool/cron/crontabs/root && crond -l 2 -f"

crond[9]: crond (busybox 1.24.1) started, log level 2
crond[9]: user:root entry:* * * * * echo foobar
crond[9]: wakeup dt=40
crond[9]: file root:
crond[9]:  line echo foobar
crond[9]:  job: 0 echo foobar
crond[10]: child running /bin/sh
crond[9]: USER root pid  10 cmd echo foobar
foobar
crond[9]: wakeup dt=10
crond[9]: wakeup dt=50
crond[9]: file root:
crond[9]:  line echo foobar
crond[9]:  job: 0 echo foobar
crond[11]: child running /bin/sh
crond[9]: USER root pid  11 cmd echo foobar
foobar

まとめ

alpine自体超軽量なのでcron程度の用途でも気軽に1コンテナ1プロセスを実現出来ていい感じ。

38
31
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
38
31