[英]Stop docker in Dockerfile if a script exited
In my Dockerfile
, I start a process using CMD: 在我的
Dockerfile
,我使用CMD启动一个过程:
# Start MyProcess
CMD ./my_process.sh >> /log/myprocess.log
my_process.sh
may exit 0
according to some conditions inside that script. 根据该脚本中的某些条件,
my_process.sh
可能会exit 0
。 Is there a way to safely stop the container from running/starting? 有没有一种方法可以安全地停止容器的运行/启动? right now, it keeps restarting indefinitely
现在,它会无限期地重新启动
You can try leveraging restart policies, add below argument during docker run
- 您可以尝试利用重启策略,在
docker run
期间添加以下参数-
docker run --restart on-failure .....
--restart on-failure
-重新启动失败
Restart only if the container exits with a non-zero exit status.
仅当容器以非零退出状态退出时才重新启动。 Optionally, limit the number of restart retries the Docker daemon attempts.
(可选)限制Docker守护进程尝试重新启动的重试次数。
Ref - https://docs.docker.com/engine/reference/commandline/run/ 参考-https: //docs.docker.com/engine/reference/commandline/run/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.