启动Rbase docker容器时如何启动cron [英] how to start cron when starting a Rbase docker container
问题描述
我正在尝试构建一个运行R和cron的docker容器。我需要的是在启动容器时使cron自动运行。
I'm trying to build a docker container which runs R and cron. What I need is make cron run automatically when I start the container.
我的dockerfile如下:
My dockerfile is like below:
# 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的状态:
Then I built the image and run container in bash. I checked the status of cron:
/etc/init.d/cron status
我的cron状态如下:
I got the cron status like below:
[FAIL] cron is not running ... failed!
我能够通过手动启动cron来启动cron:
I was able to start the cron by starting cron mannually:
/etc/init.d/cron start
我的问题是我应该如何修改我的dockerfile(行 CMD
),以便在Docker容器启动时cron自动启动?
My question is how I should modify my dockerfile (line CMD
), so that when docker container start, cron start automatically?
非常感谢。
推荐答案
CMD /etc/init.d/cron start
将启动在后台执行cron操作,以便您的容器在创建后立即死亡。
CMD /etc/init.d/cron start
will start cron in the background so your container will die as soon as it created.
在第二个选项中,添加 -f
In the second option, add -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.
但是您将无法使用 / etc / init看到cron。 d / cron状态
。
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正在运行。
You will see that the cron is running.
这篇关于启动Rbase docker容器时如何启动cron的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!