以debian bullseye 为例

DockerFile

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

COPY ./crontab /var/spool/cron/crontabs/root
RUN chmod 0644 /var/spool/cron/crontabs/root
RUN crontab /var/spool/cron/crontabs/root

COPY ./entrypoint.sh /usr/local/bin/

RUN chmod +x /usr/local/bin/entrypoint.sh

ENTRYPOINT ["bash", "entrypoint.sh" ]

crontab文件、

按crontab写入命令即可,建议在linux使用vi命令写入,windows上创建可能会报错

entrypoint.sh

#!/bin/bash

set -e

cron

exec "$@"