为什么在 dockerfile 中添加文件 /etc/crontabs/www-data 会在 运行 容器(基于 alpine)时为 www-data 生成 cron 作业

Why adding a file /etc/crontabs/www-data in dockerfile will make the cron job for www-data when run the container (alpine based)

我知道为用户 www-data 添加 cron 作业的正确方法是 运行 crontab -u www-data -e

所以要在 docker 文件中做到这一点,我应该添加一行 RUN crontab -u www-data /some_where/crontab.conf

但我发现如果我这样做,它也有效(docker图像基于alpine3.7)。

ADD /some_where/crontab /etc/crontabs/www-data
RUN chmod 0644 /etc/crontabs/www-data

但我找不到解释其工作原理的文档。那么为什么它有效,这是否意味着如果我将另一个名为 www 的文件添加到 /etc/crontabs,它将为 www 创建一个 cronjob(假设我有 www 用户)?

this:

Multiuser cron

As Unix is a multiuser OS, some of the apps have to be able to support multiple users, cron is one of these. Each user can have their own crontab file, which can be created/edited/removed by the command crontab. This command creates an individual crontab file and although this is a text file, as the /etc/crontab is, it shouldn't be edited directly. The crontab file is often stored in /var/spool/cron/crontabs/<user> (Unix/Slackware/BSD), /var/spool/cron/<user> (RedHat) or /var/cron/tabs/<user> (SuSE), but might be kept elsewhere depending on what Unx flavor you're running.

而在alpine中,它也在/var/spool/cron/crontabs中,只是/var/spool/cron/crontabs/etc/crontabs的一个符号link,所以你也可以把它放在/etc/crontabs中]:

/etc/crontabs # ls -alh  /var/spool/cron/crontabs
lrwxrwxrwx    1 root     root          13 Jun 19 17:14 /var/spool/cron/crontabs -> /etc/crontabs