Solving the docker daemon error in Jenkins jobs

Sometimes, in our Jenkins jobs - or anywhere running Docker - we get this error:

docker: Error response from daemon: open /var/run/docker/libcontainerd/containerd/b920742812291013c64042c2a2c08671a07ef795c7eccf2122aebad3f18c097c/init/shim-log.json: no such file or directory.

We’re not sure what causes this, but simply restarting the Docker daemon seems to fix it:

sudo service docker restart

So, if this happened in a Jenkins job, you could fix it by configuring the job (e.g. at https://jenkins.canonical.com/webteam/job/deploy-to-staging.mir-server.io/configure) and adding the command to the top of the job:

sudo service docker restart
exit

Now save the job and run it to restart the daemon. Then go back into “configure”, remove those two lines, and run the job again - hopefully now it should succeed.