Apline容器启动Crontab任务

Dockerfile 例子:

FROM alpine

# Copy script which should be run
COPY ./myawesomescript /usr/local/bin/myawesomescript
# Run the cron every minute
RUN echo '*  *  *  *  *    /usr/local/bin/myawesomescript' > /etc/crontabs/root

CMD ['crond', '-l 2', '-f']

如果只关心周期性运行,可以使用重启机制来实现
docker-compose.yml 例子:

version: '3.3'
services:
  letsencrypt:
    image: czerasz/letsencrypt-companion
    deploy:
      restart_policy:
        condition: any
        # Run every day
        delay: 1d

  ...

你可能感兴趣的:(Apline容器启动Crontab任务)