1 min read

Why does Docker restart all containers regularly?

Why does Docker restart all containers regularly?
Photo by Ian Taylor / Unsplash

For as long as I can remember, every now and then, all my Docker containers restart. I had no idea why.

I am running Ubuntu 16.04 LTS (Xenial).

I got the exact start time of my containers like so:

docker inspect --format='{{.State.StartedAt}}' <CONTAINERID>

(Thanks to Tim Robinson for that bit of magic.)

Then I looked in the syslog for entries around that date. (I used lnav to make that a bit easier to do.)

This is what I found:

Oct  7 06:09:52 jandell systemd[1]: Starting Daily apt upgrade and clean activities...
Oct  7 06:10:04 jandell systemd[1]: Stopping Docker Application Container Engine...

It looks like apt does stuff every morning, and as part of it, if it deems it to be required, restarts Docker. This is likely because things Docker has been using have been upgraded. Sometimes when I install or upgrade, I’ll get a full screen prompt asking which services to restart because dependent libraries have been updated. Docker is often one of the candidates.

So how do I stop this? Do I want to?

The main problem is that my nginx + docker-gen container don’t properly restart after Docker does. If I’m in charge upgrading Docker, then I can live with this and just make sure all my services are running after I do my upgrade. I don’t want the system automatically upgrading itself.

Based on the Gist “how to disable apt-daily.timer”, I’ve determined I can disable the automatic upgrade task apt-daily-upgrade.timer:

$ systemctl stop apt-daily-upgrade.timer
$ systemctl disable apt-daily-upgrade.timer
$ systemctl daemon-reload

This should hopefully stop apt from restarting things when I don’t know about it.

As to why nginx-gen doesn’t restart when it should, that’s for another time.