如何在Docker容器中管理守护程序服务

发布于 2025-02-09 10:55:53 字数 142 浏览 3 评论 0原文

我正在Docker容器内部运行Avahi-Daemon。目前,我通过简单地从组合文件运行它来开始此操作。有没有办法以“托管”的方式启动它,因此如果失败,它会自动重新启动?目前,由于缺乏Init过程,如果失败了,它将变得已删除,无法启动替换。

I'm running avahi-daemon inside of a Docker container. Currently I'm starting this by simply running it from the compose file. Is there a way to start it in a "managed" fashion, so it automatically restarts if it fails? Currently, due to the lack of an init process if it fails it becomes defunct and a replacement cannot be started.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愿得七秒忆 2025-02-16 10:55:53

看起来像您只需在没有的情况下运行它 -选项;然后,它将是一个可能是主要容器过程的前景过程。然后,您可以使用docker 如果容器失败,请重新启动容器。

最小的Dockerfile看起来像:

FROM ubuntu:20.04
RUN apt-get update \
 && DEBIAN_FRONTEND=noninteractive \
    apt-get install --no-install-recommends --assume-yes \
      avahi-daemon
CMD ["avahi-daemon", "--no-chroot"]

相应的组合设置:

version: '3.8'
services:
  avahi-daemon:
    build:
      context: .
      dockerfile: Dockerfile.avahi-daemon
    restart: on-failure

It looks like you can just run it without a --daemonize option; then it will be a foreground process that can be the main container process. You can then use a Docker restart policy to restart the container if it fails.

A minimal Dockerfile could look like:

FROM ubuntu:20.04
RUN apt-get update \
 && DEBIAN_FRONTEND=noninteractive \
    apt-get install --no-install-recommends --assume-yes \
      avahi-daemon
CMD ["avahi-daemon", "--no-chroot"]

And the corresponding Compose setup:

version: '3.8'
services:
  avahi-daemon:
    build:
      context: .
      dockerfile: Dockerfile.avahi-daemon
    restart: on-failure
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文