gpt4 book ai didi

linux - Docker 容器作为 Linux 服务?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:49:56 25 4
gpt4 key购买 nike

我刚刚创建了一个安全的 Docker Registry并在远程 VM 上运行它(使用 docker run ...)。然后我运行 docker ps 并看到它实际上正在运行。我退出机器,然后通过 SSH 重新登录。我再次运行 docker ps 并验证它在我退出 SSH session 时“幸存”。

这让我想知道:Docker 容器实际上作为 Linux 服务运行吗?如果不是,是否有任何方法可以让它们作为传统的(upstart- 或 systemd-based) 服务?这样做有什么理由/优点吗?

最佳答案

docker 引擎作为守护进程运行。
在“Host integration”中提到:

As of Docker 1.2, restart policies are the built-in Docker mechanism for restarting containers when they exit. If set, restart policies will be used when the Docker daemon starts up, as typically happens after a system boot. Restart policies will ensure that linked containers are started in the correct order.

If restart policies don’t suit your needs (i.e., you have non-Docker processes that depend on Docker containers), you can use a process manager like upstart, systemd or supervisor instead.


顺便说一句,这涉及(当容器运行时带有某些选项)一些安全问题:参见 issue 14767issue 6401 :

The container (with --net host option) is the host when it comes to the network stack so any services running on the host are accessible to the container. It just so happens that you communicate to upstart ( and others ) this way.

This feature is a runtime only option, just like the --privileged flag, therefore an image cannot request this, it must be explicitly set at runtime.

关于linux - Docker 容器作为 Linux 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32666546/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com