Sitemap

How Does Docker Engine Live-Restore Work? A Simple Guide

3 min readMar 13, 2024

--

Press enter or click to view image in full size

In this post, we’re going to examine what happens if our container is running and, for whatever reason, the dockerd service or the Docker daemon goes down, how we should configure our Docker to make our containers more resilient. When the Docker daemon stops temporarily, all containers are shutdown unless we have previously activated the live-restore feature.

Introduction

Many of us use Docker to deploy our code or quickly set up a service (like nginx or mongodb). Docker provides an isolated environment where we can easily configure the setting in which our code runs, assign it a network, allocate the amount of CPU, RAM, and other desired resources, and execute our code in it.

For example, imagine we are going to deploy a simple Nginx web server. We can pull and run an Nginx image from Docker Hub website using docker run command:

hesam@TheHesamGh:~$  docker run -it -d --restart always -p 8080:80 --name web nginx
fe07d3773e6f00861c9b59f366c09b5e4cac24c83256bfc1d851ad8ccc3036c3

Note: You should run the container using --restart alway switch to ensure live restore works for your container (I personally tested and it haven’t worked without this, please give me any details in comments below about this).

What happens to the running containers if restart the Docker service?

Docker containers run on the Docker daemon. According to docker docs:

The Docker daemon (dockerd) listens for Docker API requests and manages Docker objects such as images, containers, networks, and volumes. A daemon can also communicate with other daemons to manage Docker services.

The problem arises when the Docker daemon might restart or be unavailable for a few moments (for updates to the Docker Engine itself). What happens next for the running containers? The service we’re running in the container goes down for a moment. As you can see in the following, after restarting the Docker daemon, no running container exists.

hesam@TheHesamGh:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fe07d3773e6f nginx "/docker-entrypoint.…" 54 seconds ago Up 53 seconds 0.0.0.0:8080->80/tcp, :::8080->80/tcp web
hesam@TheHesamGh:~$
hesam@TheHesamGh:~$ systemctl restart docker
hesam@TheHesamGh:~$
hesam@TheHesamGh:~$ docker ps
CONTAINER ID IMAGE
hesam@TheHesamGh:~$

While this might not be a problem in the development environment, it can be very bad if our code is running in production, potentially upsetting customers.

What is the solution?

To solve this problem, we can configure the Docker daemon in such a way that it can restore itself while our containers are running, known as “live-restore”.

Get Hesamedin Ghasemi’s stories in your inbox

Join Medium for free to get updates from this writer.

I don’t want to get into too much detail on how to configure it, but for those familiar with Docker, you simply need to open `/etc/docker/daemon.json` file and add the following value to it:

{
"live-restore": true
}

Check what happens after enabling live-restore

After enabling live-restore, the running container will not be affected if docker daemon gown down for some moments…

hesam@TheHesamGh:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4e805cd91384 nginx "/docker-entrypoint.…" 3 seconds ago Up 3 seconds 0.0.0.0:8080->80/tcp, :::8080->80/tcp web
hesam@TheHesamGh:~$
hesam@TheHesamGh:~$ systemctl restart docker
hesam@TheHesamGh:~$
hesam@TheHesamGh:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4e805cd91384 nginx "/docker-entrypoint.…" 11 seconds ago Up 11 seconds 0.0.0.0:8080->80/tcp, :::8080->80/tcp web

For more details read the link below: https://docs.docker.com/config/containers/live-restore/

I greatly appreciate you taking the time to read my article. If you enjoyed it, please don’t hesitate to leave a clap 👏🏻

--

--