Automatically restart docker daemon if there are no running containers
https://askubuntu.com/questions/1565604/automatically-restart-docker-daemon-if-there-are-no-running-containersMy installation pauses when a manual APT update and install (sudo apt full-upgrade) includes a new version of docker.io on one of my systems .. this requires me to type yes to restart the daemon, despite there being no running containers to impact
This is accompanied by a reasonable message, which rationalizes offering to restart the daemon
If Docker is upgraded without restarting the Docker daemon, Docker will often have trouble starting new containers, and in some cases even maintaining the containers it is currently running. See https://launchpad.net/bugs/1658691 for an example of this breakage.
Normally, upgrading the package would simply restart the associated daemon(s). In the case of the Docker daemon, that would also imply stopping all running containers (which will only be restarted if they're part of a "service", have an appropriate restart policy configured, or have some other means of being restarted such as an external systemd unit).
Automatically restart Docker daemon? [yes/no]
I've found some suggestions to blanket enable noninteractive mode (which never asks questions, always choosing the default, yes), but that's not granular enough for me and will restart the daemon even when containers are (still) running
What is the most practical way to always and automatically restart the daemon on a new version install (or other apt interactions?) if there are no running containers? I do want to be asked and the restart waited on, but only when there are running containers .. though as a stretch goal, ensuring there are also no building containers would be an advantage!
I imagine a script can be added somewhere (apt, debconf?) to provide or override the default behavior like this
#!/bin/sh
# docker ps
# only output container IDs
# grep
# don't output matches, returncode is 0 for matched, 1 for unmatched
# trailing dot matches any container ID(s)
docker ps --quiet | grep --quiet .
If there's no sensible and "official" way of doing this, I feel like I should add a script into my updating workflow to add the wait myself, then debconf away this specific question, but I'm not certain
My system specifically is running 24.04.4 server (noble LTS) with desktop-minimal installed on a physical workstation which I'm using it for development, though I also suspect both the issue is more general and many users choose noninteractive
complete, relevant output during apt use, above is embedded in a quote to ensure readable wrapping
Setting up docker.io (29.1.3-0ubuntu3~24.04.1) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 79.)
debconf: falling back to frontend: Readline
Configuring docker.io
---------------------
If Docker is upgraded without restarting the Docker daemon, Docker will often have trouble starting new containers, and in some cases even maintaining the containers it is currently running. See https://launchpad.net/bugs/1658691 for an example of this breakage.
Normally, upgrading the package would simply restart the associated daemon(s). In the case of the Docker daemon, that would also imply stopping all running containers (which will only be restarted if they're part of a "service", have an appropriate restart policy configured, or have some other means of being restarted such as an external systemd unit).
Automatically restart Docker daemon? [yes/no]
Automatically restart Docker daemon? [yes/no] yes
note that yes is not the default and something needs to be typed, mildly increasing frustration




