docker - 重新启动 docker 服务会杀死所有容器吗?

标签 docker ubuntu

我在使用 docker 时遇到问题 docker ps不会返回并被卡住。
我发现做 docker service restart 之类的sudo service docker restart (https://forums.docker.com/t/what-to-do-when-all-docker-commands-hang/28103/4)
但是我担心它是否会杀死所有正在运行的容器? (我猜该服务确实提供服务以便 docker 容器可以运行?)

最佳答案

在默认配置中,您的假设是正确的:If the docker daemon is stopped, all running containers are shut down. .但是,如链接中所述,可以在 docker >= 1.12 上更改此行为通过添加

{
  "live-restore": true
}
/etc/docker/daemon.json . Crux:必须重新启动守护程序才能使此更改生效。请注意实时重新加载的限制,例如仅支持补丁版本升级,不支持主要版本升级。
另一种可能性是define a restart policy when starting a container .为此,请将下列值之一作为命令行参数 --restart 的值传递。通过 docker run 启动容器时:
no                Do not automatically restart the container. (the default)
on-failure        Restart the container if it exits due to an error, which manifests
                  as a non-zero exit code.
always            Always restart the container if it stops. If it is manually stopped,
                  it is restarted only when Docker daemon restarts or the container 
                  itself is manually restarted. 
                  (See the second bullet listed in restart policy details)
unless-stopped    Similar to always, except that when the container is stopped
                  (manually or otherwise), it is not restarted even after Docker
                  daemon restarts.
对于您的具体情况,这意味着您可以:
  • 使用 --restart always 重新启动所有容器(更多内容见下文)
  • 重新配置 docker 守护进程以允许实时重新加载
  • 重新启动 docker 守护程序(尚未配置为实时重新加载,但将在此重新启动后)

  • 此重新启动将关闭,然后重新启动所有容器一次。但从那时起,您应该可以在容器不终止的情况下自由停止 docker 守护进程。

    处理主要版本升级
    如上所述,实时重载无法处理主要版本升级。对于主要版本升级,必须拆除所有正在运行的容器。使用 always 的重启策略,但是,升级后重新启动 docker 守护程序后,容器将重新启动。

    关于docker - 重新启动 docker 服务会杀死所有容器吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63434189/

    相关文章:

    flash - 有没有类似于 FlashDevelop for Ubuntu 的工具?

    mongodb - 使用docker mongodb和laravel之间没有连接

    在构建时使用卷构建 Docker

    android - 每次执行docker run ./gradlew命令时,它都会下载所有gradle文件和依赖项。如何仅下载和安装一次?

    Android Studio 打开JDK 报错Ubuntu 16.04

    ruby - 使用 passenger + nginx 设置的 ruby​​ 应用程序上的 session 随机丢失

    ubuntu - 无法使用 apt-get 在 Ubuntu 14.04 上安装 bazel

    mysql - TravisCI - 是否可以启动 docker 服务并期望 mysql 正常工作?

    mongodb - 如何在MongoDB 3.6的Docker镜像中启用更改流?

    ubuntu - 如何使用ansible设置FQDN?