简体   繁体   English

启动 Rbase docker 容器时如何启动 cron

[英]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.

相关问题 使用 docker、rbase 和 RODBC 连接到 sql 服务器时出错 - Error connecting to sql server with docker, rbase, and RODBC 部署到 Google Cloud Run 时 Docker 容器无法启动 - Docker container failed to start when deploying to Google Cloud Run 如何启动 Docker 容器并告诉 R 使用在所述容器中运行的特定版本的系统依赖项? - How can I start a Docker container and tell R to use a specific version of a system dependency being run in said container? Docker:如何将RCurl安装到Docker容器? - Docker: how to install RCurl to Docker container? 当API在Docker容器中运行时,如何使用R Plumber中创建的API? - How to consume from API created in R Plumber when API runs in Docker Container? 在Docker容器中绘图时Jupyter R崩溃 - Jupyter R crashes when plotting in docker container 如何重启Docker容器中的shiny服务器? - How to restart shiny server in Docker container? 启动Rocker容器时,从附加卷中打开RStudio Project - Open RStudio Project from the attached volume when starting Rocker container 在Docker容器中安装R软件包时缺少&#39;aclocal-1.14&#39; - 'aclocal-1.14' is missing when installing R package in docker container 如何在 Docker 容器中运行 R Shiny App - How to run R Shiny App in Docker Container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM