We all know that Docker is a C/S model architecture, which uses the client (CLI) to access Docker Daemon to create and manage containers. By default, when the daemon terminates, it will stop all running containers.
Therefore, when we need to upgrade the Docker Daemon or some maintenance operations that need to be restarted, we need to cause the running container to restart.
Live Restore
In fact, Docker provides a feature that can keep the container running when Daemon is unavailable, which reduces the downtime of the container when Daemon is upgraded or there is a problem. Then this feature is called Live Restore.
Enable the Live Restore feature by adding the following configuration to Docker Daemon. On Linux, add in the default configuration file /etc/docker/daemon.json
{
"live-restore": true
}
Then restart the docker service. If you use systemd to manage the service, you can avoid restarting the docker service through reload
sudo systemctl reload docker.service
In other cases, you can send the SIGHUP signal to the dockerd process.
For Docker Desktop on Windows and MacOS, Live Restore can be turned on through the Daemon advanced configuration of the Desktop program.
After the configuration is complete, you can try to restart the Docker Daemon to see if the container will keep running. Check the startup time of the container before restarting
WSL - mengz docker container inspect portainer_edge_agent -f '{{ .State.StartedAt }}'
2021-12-18T09:50:59.761725785Z
Then execute sudo systemctl restart docker.service
. After querying the startup time of the container once, you will find that the startup time has not changed, which means that the container has not restarted.
Limitations of Live Restore
The current Live Restore feature can be used for Daemon maintenance or unavailability due to a problem with Daemon, reducing the downtime of the container, but it also has certain limitations.
Docker version upgrade restrictions
Live Restore is only available when the Docker patch version is upgraded, that is, the upgrade where the last digit of YY.MM.x has changed, and does not support the upgrade of major versions. After a major version upgrade, Daemon may not be able to reconnect to the running container. At this time, you need to manually stop the running container.
Daemon option changes
In other words, Live Restore only works when certain Daemon-level configuration options do not change, such as Bridge IP address, storage drive type, etc. If these options are changed when Daemon is restarted, it may be that Daemon cannot reconnect to the running containers, and you need to stop these containers manually.
Affect the log output of the container
If Daemon stops for a long time, it will affect the log output of the running container. Because the buffer size of the log pipeline is 64k by default, when the buffer is full, Daemon must be started to refresh the buffer.
Does not support Docker Swarm
Live Restore is just a feature of the independent Docker engine, and the Swarm service is managed by the Swarm manager. When the Swarm manager is unavailable, the Swarm service can continue to run on the worker nodes, but it is not managed through the Swarm manager until the Swarm management resumes work.
Summarize
Through the live-restore feature of Docker Daemon, we can run daemonless containers, which can reduce the downtime of container applications when maintaining Docker Daemon, but there are also certain restrictions when used, such as Restrictions on upgrading the engine version. If you are concerned about containers without daemons, you can learn more about Podman .
Most of the above content comes from Docker's official documents. For more detailed information, please refer to https://docs.docker.com/config/containers/live-restore/ .
The article was published simultaneously on Mengz's Blog
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。