We all know that Docker is a C/S model architecture, where containers are created and managed by accessing the Docker Daemon through a client (CLI). By default, when the daemon terminates, it stops all running containers.

So when we need to upgrade the Docker Daemon or perform some maintenance operations that require restarting, we need to cause the running containers to restart along with it.

Live Restore

In fact, Docker provides a feature that keeps containers running when Daemon is unavailable, thus reducing container downtime when Daemon is upgraded or has problems. That feature is called Live Restore.

Enable the Live Restore feature by adding the following configuration to the Docker Daemon configuration file (on Linux, the default configuration file is at /etc/docker/daemon.json).

1
2
3
{
  "live-restore": true
}

Then restart the docker service. If you use systemd to manage the service, you can avoid restarting the docker service by reloading it.

1
sudo systemctl reload docker.service

In other cases, a SIGHUP signal can be sent to the dockerd process.

For Docker Desktop on Windows and MacOS, Live Restore can be enabled via the Daemon advanced configuration in the Desktop program.

Once configured, you can try restarting Docker Daemon to see if the container will stay up and running. Check the container’s startup time before restarting.

1
2
WSL - mengz docker container inspect portainer_edge_agent -f '{{ .State.StartedAt }}'
2021-12-18T09:50:59.761725785Z

Then execute sudo systemctl restart docker.service and check the start time of the container once, you will find that the start time has not changed, which means the container has not been restarted.

Limitations of Live Restore

The current Live Restore feature can reduce container downtime while performing Daemon maintenance, or in the event of Daemon problems resulting in unavailability, although it does have certain limitations.

  1. Docker version upgrade limitation

    Live Restore only supports Docker patch version upgrade, i.e., the upgrade when the last digit of YY.MM.x changes, but not the upgrade of large versions. After a major version upgrade, it may cause the problem that Daemon cannot reconnect to the running container, and then you need to stop the running container manually.

  2. Daemon option changes

    That is, Live Restore only works when certain Daemon level configuration options do not change, such as the Bridge IP address, storage drive type, etc.. If these options change when restarting Daemon, it may be impossible for Daemon to reconnect to the running containers, and it is necessary to stop these containers manually.

  3. Affect the log output of the container

    If Daemon is stopped for a long time, it will affect the log output of the running container. Because by default, the buffer size of the logging pipeline is 64k, when the buffer is full, Daemon must be started to flush the buffer.

  4. Docker Swarm is not supported

    Live Restore is only a feature of the standalone Docker engine, while Swarm’s services are managed by the Swarm manager. When Swarm Manager is not available, Swarm services are allowed to continue running on the working node, just differently managed through Swarm Manager until Swarm Management is back in action.

Summary

The live-restore feature of Docker Daemon allows us to run daemonless containers, which reduces the downtime of container applications when maintaining the Docker Daemon, but there are some limitations to its use, such as restrictions on upgrading engine versions. If you are concerned about daemonless containers, you can learn more about Podman.

Most of the above is taken from the official Docker documentation. For more detailed information, please refer to https://docs.docker.com/config/containers/live-restore/.