Ubuntu – systemd does not stop Docker Application Container Engine

18.04dockersystemd

Issue: Every time I reboot or shut down, I have to wait an arbitrary number of minutes due to systemd when it tries to stop the Docker Application Engine.

System:

  • xubuntu 18.04 on a Lenovo Thinkpad x260
  • DISTRIB_ID=Ubuntu
    DISTRIB_RELEASE=18.04
    DISTRIB_CODENAME=bionic
    DISTRIB_DESCRIPTION="Ubuntu 18.04.1 LTS"
  • docker installed via apt
  • docker --version gives Docker version 18.09.0-ce-tp5, build 9eb3d36
  • systemctl --version gives systemd 237
    +PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN2 +IDN -PCRE2 default-hierarchy=hybrid
  • No containers are running at the time of the shutdown request. I explicitly stopped and removed them beforehand (docker container ls --all shows nothing).

Behavior: After I click the "Shutdown" or "Reboot" button, the GUI shuts down and shows the xubuntu logo with a spinning icon. Pressing Esc, I am welcomed by the systemd service status screen. Only 2-3 lines occur (as can be seen in the photo below), then I have to wait arbitrarily long (values between 1min and 25min actively observed). Because I cannot ensure that systemd will terminate any time soon, I usually use the hardware button to shutdown my machine. This issue occurs since I have docker installed on my system.

photograph of systemd messages

[ OK ] Started Show Plymouth Power Off Screen.
[   *] A stop job is running for Docker Application Container Engine (14s / no limit)[ OK ] Started Show Plymouth Power Off Screen.
[ ** ] A stop job is running for Docker Application Container Engine (24min 27s / no limit)

Question: how can I make docker stop gracefully?

Best Answer

I occasionally have this issue and I'm not sure why docker has hung. But what I have found is that the timeout is explicitly set to unlimited in the service file deployed by docker-ce:

$ grep Timeout /lib/systemd/system/docker.service 
TimeoutSec=0

To avoid this hanging for extended periods I set the TimeoutStopSec parameter in an override:

$ sudo systemctl edit docker.service

Add the following lines:

[Service]
TimeoutStopSec=300

Then reload:

$ sudo systemctl daemon-reload
Related Question