简体   繁体   English

在 Ubuntu docker 容器中崩溃时自动重启进程

[英]Automatically restart process on crash in an Ubuntu docker container

I have a process in an Ubuntu docker container.我在 Ubuntu docker 容器中有一个进程。 If it crashes, I want to restart it automatically.如果它崩溃了,我想自动重新启动它。 What is the best way to go about it?最好的方法是什么? I checked systemd (which is the normal Linux method) but docker doesn't support it.我检查了 systemd(这是正常的 Linux 方法),但 docker 不支持它。 inittab is also deprecated. inittab 也已弃用。

Docker offers such functionality, all you have to do is to define a restart policy for the container. Docker 提供了这样的功能,你所要做的就是为容器定义一个重启策略

You should choose one of the available policies no , always , on-failure , unless-stopped and adjust your docker run command accordingly.您应该选择一种可用策略noalwayson-failureunless-stopped并相应地调整您的docker run命令。

From docs:从文档:

To configure the restart policy for a container, use the --restart flag when using the docker run command要为容器配置重启策略,请在使用 docker run 命令时使用 --restart 标志

For your case, choose one of always or on-failure .对于您的情况,请选择alwayson-failure

Note : The above is valid only if the process you have mentioned is the container's entrypoint.注意:以上仅当您提到的进程是容器的入口点时才有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM