[英]how to start cron when starting a Rbase docker container
I'm trying to build a docker container which runs R and cron.我正在尝试构建一个运行 R 和 cron 的 docker 容器。 What I need is make cron run automatically when I start the container.
我需要的是让 cron 在我启动容器时自动运行。
My dockerfile is like below:我的 dockerfile 如下所示:
# Install R version 3.6
FROM r-base:3.6.0
#install crontab
RUN apt-get update && apt-get -y install cron
# also tried CMD /etc/init.d/cron start
CMD cron
Then I built the image and run container in bash.然后我在 bash 中构建镜像并运行容器。 I checked the status of cron:
我检查了cron的状态:
/etc/init.d/cron status
I got the cron status like below:我得到了如下的cron状态:
[FAIL] cron is not running ... failed!
I was able to start the cron by starting cron mannually:我可以通过手动启动 cron 来启动 cron:
/etc/init.d/cron start
My question is how I should modify my dockerfile (line CMD
), so that when docker container start, cron start automatically?我的问题是我应该如何修改我的 dockerfile (行
CMD
),以便当 docker 容器启动时,cron 自动启动?
Thanks a lot in advance.提前非常感谢。
CMD /etc/init.d/cron start
will start cron in the background so your container will die as soon as it created. CMD /etc/init.d/cron start
将在后台启动 cron,因此您的容器将在创建后立即死亡。
In the second option, add -f
在第二个选项中,添加
-f
# Install R version 3.6
FROM r-base:3.6.0
#install crontab
RUN apt-get update && apt-get -y install cron
# also tried CMD /etc/init.d/cron start
CMD [ "cron", "-f" ]
So it will keep your container running.所以它会让你的容器保持运行。
-f
Stay in foreground mode, don't daemonize.
But you will not able to see the cron using /etc/init.d/cron status
.但是您将无法使用
/etc/init.d/cron status
查看 cron。 use below dokcerfile.在 dokcerfile 下面使用。
FROM r-base:3.6.0
RUN apt-get update && apt-get -y install cron
RUN apt-get install procps -y
CMD ["cron" ,"-f"]
and then run然后运行
docker exec -it <your_container_id> bash -c "ps -aux"
You will see that the cron is running.您将看到 cron 正在运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.