更新后容器未重新启动并始终在 docker-compose.yml 中重新启动 [英] Containers not restarted after update with restart always in docker-compose.yml

查看:42
本文介绍了更新后容器未重新启动并始终在 docker-compose.yml 中重新启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些容器,它们都在 docker-compose 文件中具有 always restart 值,如下所示:

I have some containers which all of them have the always restart value in the docker-compose file like this:

version: "3.7"
services:

  container:
    image: ghost:latest
    container_name: some_container
    restart: always
    depends_on:
       - ...
    ports:
       - ...
...

一旦操作系统(Flatcar Linux/CoreOS)自我更新,所有容器都不会重新启动.但是,如果我只执行 $ sudo docker ps 所有容器都会立即启动.这是怎么回事,我该如何修复它以便我的容器在更新后自动重新启动?

As soon as the OS (Flatcar Linux / CoreOS) has updated itself none of the containers restart. But if I just do $ sudo docker ps all of the containers starts at once. Whats up with that and how do I fix it so my containers automatically restarts after an update?

不确定我的问题有什么不清楚的地方,restart: always 已打开.除非我在文档中遗漏了一些重要的东西,否则即使 docker 守护进程重新启动(在操作系统重新启动后),此命令也应该重新启动容器.

Not sure what is unclear about my question, restart: always is turned on. Unless I'm missing some vital thing in the documentation, this command should restart the container even if the docker daemon is restarted (after an os reboot).

从下面复制我的评论:

好的,请帮帮我.正如你在我的问题中看到的,我有重启:始终开启.所有这些容器都已启动成功并运行良好.然后操作系统更新自身自动并重新启动.在此之后重新启动docker守护进程重新启动.但由于某些原因,我运行的容器WITH RESTART: ALWAYS 不启动.如果我进入我的服务器此时,输入 sudo docker ps 列出我正在运行的容器,突然所有容器都启动了,我看到了列表.所以为什么即使守护程序正在运行,容器也没有启动吗?

Ok, so help me out here. As you can see in my question, I have restart: always turned on. All these containers are started successfully and are running well. Then the OS updates itself automatically and restarts itself. After this restart the docker daemon is restarted. But for some reasons the containers I had running WITH RESTART: ALWAYS turned on DOES NOT START. If I enter my server at this moment, type sudo docker ps to list my running containers, suddenly all containers are booted up and I see the list. So why wasn't the containers started, even though the daemon is running?

推荐答案

从评论看来,docker 服务未配置为在启动时自动启动.Docker 是一个客户端服务器应用程序,服务器从 systemd 运行,并为客户端使用的 docker 套接字提供单独的服务以与服务器通信.因此,任何使用 docker 命令的调用都可能通过点击 docker 套接字来启动服务器.

From the comments it appears the docker service was not configured to automatically start on boot. Docker is a client server app, and the server runs from systemd with a separate service for the docker socket used by the client to talk to the server. Therefore it's possible for any call with the docker command to cause the server to get launched by hitting the docker socket.

systemd 中的服务状态可以通过以下方式检查:

The service state in systemd can be checked with:

systemctl status docker

或者您可能想检查:

systemctl is-enabled docker

可以手动启动:

systemctl start docker

并且可以启用以下内容:

And it can be enabled to start with:

systemctl enable docker

以上所有命令都需要以root身份运行.

All of the above commands need to be run as root.

这篇关于更新后容器未重新启动并始终在 docker-compose.yml 中重新启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆