如何在Docker中使用永久CLI?
我正在Dockerizing我的每一个项目,我使用一个叫forever
的CLI来重新运行我的脚本,如果他们失败了。
我正在使用官方的node.js Docker教程来对我的简单脚本进行Dockerize,但是当我遇到了更复杂的脚本(使用forever
CLI )时,我不知道如何在Docker中运行CLI。
有没有什么办法可以做到这一点,无论是使用forever
CLI或模块 ?
我会重申奥利弗的评论,因为我认为这实际上是一个有效的答案。 当作为一个Docker容器运行一个进程时,已经有一些机制来处理forever
为你做的事情。
对forever
行为的快速反应显示,它实际上已经看起来有点像Docker:
actions: start Start SCRIPT as a daemon stop Stop the daemon SCRIPT by Id|Uid|Pid|Index|Script stopall Stop all running forever scripts restart Restart the daemon SCRIPT restartall Restart all running forever scripts list List all running forever scripts config Lists all forever user configuration set <key> <val> Sets the specified forever config <key> clear <key> Clears the specified forever config <key> logs Lists log files for all forever processes logs <script|index> Tails the logs for <script|index> columns add <col> Adds the specified column to the output in `forever list` columns rm <col> Removed the specified column from the output in `forever list` columns set <cols> Set all columns for the output in `forever list` cleanlogs [CAREFUL] Deletes all historical forever log files
而不是forever
使用来pipe理你的过程,只需使用Docker:
-
--restart=always
docker run
的--restart=always
选项是forever
相同的底层概念,重启应用程序并在失败时保持运行。 -
docker run
是forever start
代名词。 将-d
添加到docker run
运行在后台运行。 -
docker ps
是forever list
代名词。 在Docker的情况下,使每个forever
进程都是Docker容器。 -
docker logs
是forever logs
代名词。
这应该使得在Dockerfile
进程设置为CMD
或ENTRYPOINT
变得相当简单,并且完全消失。
更进一步,当你开始进入容器编排和部署时,看看健康检查( HEALTHCHECK
指令),Docker Swarm和Docker Compose。