How to restart docker systemd without restarting docker containers

Notes

I wanted to update the Docker image source, but I was hesitant because reloading the new configuration with systemctl restart docker would shut down other people’s containers—and I’d get beaten up for it.

Now, based on the idea provided by @akkuman, using "live-restore": true allows me to apply new configurations immediately after modification. Finally, I can pull images painlessly!

PS: For currently available Docker mirror sources, see 国内可用docker镜像源

Main Article

Translated by SimpRead, original URL yuansmin.github.io

Experiencing memory leaks in dockerd in production? Wanting to restart dockerd but afraid of restarting containers and affecting live services?

Don’t worry! Use docker live-restore—when restarting dockerd, your containers will not be restarted.

1. Configure the docker daemon parameters. Edit the file /etc/docker/daemon.json, and add the following configuration:

{
    "live-restore": true
}

2. Reload dockerd configuration (this does not restart dockerd—so convenient for applying config changes!)

kill -SIGHUP $(pidof dockerd)  # Send SIGHUP signal to dockerd; dockerd reloads configuration upon receiving it

3. Verify that the configuration is successful

docker info | grep -i live
# You should see: Live Restore Enabled: true

4. Restart Docker—containers will NOT be restarted this time

systemctl restart docker
This is incredibly useful. Now you can restart dockerd whenever there’s an issue without worrying about impacting running services. For example:
  1. Upgrading Docker version
  2. Docket memory leak issues—common in Docker versions before 17.06. No more fear of dockerd consuming all memory and being unable to restart!

Docker supports reloading configuration without restarting, using the SIGHUP signal—just like nginx -s reload. Very handy.

Additional Note:

If any container mounts the docker.sock file, it may malfunction after a restart and require restarting the container. The reason is that the inode of the docker.sock file changes after dockerd restarts. See more details at The Pitfall of Mounting a Single Docker File.

Reference: Docker documentation https://docs.docker.com/config/containers/live-restore/