【发布时间】:2018-08-25 04:54:01
【问题描述】:
我想使用 alpine(因为它创建一个轻量级图像)和一个 cron(定期执行任务)创建一个 docker 文件,作为一个新手,我最初尝试使用 ubuntu 它工作得很好,因为我从中得到了帮助链接UbuntuExample with CRON
现在的问题是它创建了沉重的 docker 镜像。我想将这个相同的示例转换为 alpine,但找不到完美的帮助。搜索了很多网站,但没有任何收获。
主要任务:-
我的主要任务是通过 docker 执行一个 java jar 文件并定期执行该 jar 文件
到目前为止,我尝试创建一个简单的 docker 文件和一个 crontab 文件,只是为了定期打印消息。
我面临的主要问题是在 alpine 上安装 cron。
DOCKERFILE (DockerFile)
FROM ubuntu:latest
MAINTAINER docker@ekito.fr
# Add crontab file in the cron directory
ADD crontab /etc/cron.d/hello-cron
# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/hello-cron
# Create the log file to be able to run tail
RUN touch /var/log/cron.log
#Install Cron
RUN apt-get update
RUN apt-get -y install cron
# Run the command on container startup
CMD cron && tail -f /var/log/cron.log
CRONTAB (crontab)
* * * * * root echo "Hello world" >> /var/log/cron.log 2>&1
# Don't remove the empty line at the end of this file. It is required to run the cron job
这对于 ubuntu 来说是完美的,但是如何在 openjdk:8-jre-alpine 中实现它
【问题讨论】:
-
图片
openjdk:8-jdk-alpine已经安装了crontab和java。 -
你能帮我用cron写一个简单的dockerfile来打印一个简单的语句,这样我就可以写它来执行我的jar文件