[英]Error connecting to sql server with docker, rbase, and RODBC
[英]how to start cron when starting a Rbase docker container
我正在嘗試構建一個運行 R 和 cron 的 docker 容器。 我需要的是讓 cron 在我啟動容器時自動運行。
我的 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
然后我在 bash 中構建鏡像並運行容器。 我檢查了cron的狀態:
/etc/init.d/cron status
我得到了如下的cron狀態:
[FAIL] cron is not running ... failed!
我可以通過手動啟動 cron 來啟動 cron:
/etc/init.d/cron start
我的問題是我應該如何修改我的 dockerfile (行CMD
),以便當 docker 容器啟動時,cron 自動啟動?
提前非常感謝。
CMD /etc/init.d/cron start
將在后台啟動 cron,因此您的容器將在創建后立即死亡。
在第二個選項中,添加-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" ]
所以它會讓你的容器保持運行。
-f
Stay in foreground mode, don't daemonize.
但是您將無法使用/etc/init.d/cron status
查看 cron。 在 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"]
然后運行
docker exec -it <your_container_id> bash -c "ps -aux"
您將看到 cron 正在運行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.