Search code examples
dockerupgraderestartapt-get

Prevent Docker-Engine restart during apt-get upgrade


I've got an issue here with Ubuntu 14.04

Whenever I do an apt-get upgrade, if docker-engine is eligible for upgrade, it restarts the service after upgrading. This causes the containers to get restarted.

One of the containers is one that requires manual intervention during startup, others are gathering time-critical data, so that a restart of the containers is only desired at very specific times.

How can I exclude the docker-engine service from these automatic restarts?

AFAIK, mongodb, for instance, doesn't restart mongod after an apt-get upgrade, why can't docker behave the same way?


Solution

  • I am not entirely sure what mongodb does but I am pretty sure it does restart itself on update.

    The problem with docker-engine is not that it doesn't restart itself, it actually does, which you can verify by running the following command after update:

    sudo service docker status
    

    It's just that it doesn't restart the running containers. I don't exactly know why it has to be like this because it could in theory be able to bring back the running containers if the service is restarted but for whatever reason, it doesn't do it.

    There are two ways to workaround this issue.

    The first and easy way it to exclude the update of docker-engine and do the update manually if you see it is available.

    sudo apt-mark hold docker-engine
    sudo apt-get upgrade
    

    You should see a notice if there was an update and if the update was kept back

    ...
    The following packages were kept back:
    docker-engine
    ...
    

    If you have containers that you cannot afford to restart at upgrade, you should go this route.

    If however, you can afford to have them restarted, you can use the second approach. You can set restart policies when you start the containers, like so:

    sudo docker run --restart=always -d image-name
    

    This way, when docker-engine is restarted, the container is started with it. This means that on update, the container started this way gets started automatically.