在 docker 上启用实时恢复并不能使容器保持活动状态

Enabling live restore on docker isn't keeping the containers alive

我读了Enable Live Restore,但是当我试过的时候。

ubuntu@ip-10-0-0-230:~$ cat /etc/docker/daemon.json 
{
  "live-restore": true
}

我在分离模式下启动了一个 nginx 容器。

sudo docker run -d  nginx
c73a20d1bb620e2180bc1fad7d10acb402c89fed9846f06471d6ef5860f76fb5 


$sudo docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              
 
c73a20d1bb62        nginx               "nginx -g 'daemon of…"   5 seconds ago       Up 4 
seconds

然后我停止了 dockerd

sudo systemctl stop snap.docker.dockerd.service

而且我检查过没有容器运行

ps aux | grep nginx

之后,我重新启动了 docker 服务,但仍然没有任何容器。

有什么想法吗?这个“启用实时恢复”是如何工作的?

documentation 修改 daemon.json(添加 "live-restore": true)后,您需要:

Restart the Docker daemon. On Linux, you can avoid a restart (and avoid any downtime for your containers) by reloading the Docker daemon. If you use systemd, then use the command systemctl reload docker. Otherwise, send a SIGHUP signal to the dockerd process.

您也可以这样做,但不推荐这样做:

If you prefer, you can start the dockerd process manually with the --live-restore flag. This approach is not recommended because it does not set up the environment that systemd or another process manager would use when starting the Docker process. This can cause unexpected behavior.

看来你没有做这一步。你说你修改了daemon.json,直接启动了一个容器,然后停止了dockerd

为了使 Live Restore 功能发挥作用,请按照正确的顺序执行所有步骤:

  1. 通过添加 "live-restore": true
  2. 修改 daemon.json
  3. 使用以下命令重新加载 Docker 守护程序

    sudo systemctl reload docker
    

然后 使用您的示例尝试功能(启动容器并使守护进程不可用)。

我已经测试过,如果您按顺序执行以下步骤,它会起作用:

使用 Docker version 19.03.2, build 6a30dfcUbuntu 19.10 (Eoan Ermine)

进行了测试

您已经通过 snap 安装了 Docker:snap.docker.dockerd.service

很遗憾,不推荐,因为 snap model is not fully compatible with Docker. Furthermore, docker-snap is no longer maintained by Docker, Inc. Users encounters some issues when they installed Docker via snap see 1 2

您应该删除 snap Docker 安装,以避免通过此命令出现任何潜在的重叠安装问题:

sudo snap remove docker --purge

然后安装 Docker 和 official way,然后按照上述步骤尝试 Live Restore 功能。

重新启动守护程序时也要小心,文档中说:

Live restore upon restart

The live restore option only works to restore containers if the daemon options, such as bridge IP addresses and graph driver, did not change. If any of these daemon-level configuration options have changed, the live restore may not work and you may need to manually stop the containers.

关于停机时间:

Impact of live restore on running containers

If the daemon is down for a long time, running containers may fill up the FIFO log the daemon normally reads. A full log blocks containers from logging more data. The default buffer size is 64K. If the buffers fill, you must restart the Docker daemon to flush them.

On Linux, you can modify the kernel’s buffer size by changing /proc/sys/fs/pipe-max-size.