skip to content
Jakub Szafran

Issue with Docker: not working correctly after server reboot

/ 2 min read

Problem’s description

I recently came across a weird issue regarding Docker service.

I needed Docker service to be started automatically after server’s reboot (or, more specifically, I needed Docker service to be running after reboot so an application deployed with docker-compose could start).

Docker documentation

According to Docker’s documentation, that should be pretty easy:

sudo systemctl enable docker.service
sudo systemctl enable containerd.service

Moreover, docs says that, on Ubuntu, Docker is configured to start on boot by default and no additional work was required in my case.

But it was not working as expected.


Whenever I tried to start application with docker-compose after fresh reboot, I’d see below error:

docker.errors.DockerException: Error while fetching server API version

Listing docker processes with

docker ps

would result in:

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

But /var/run/docker.sock file existed and it had appropriate owner & group. When browsing processes with

ps aux | grep docker

I could see that Docker daemon was running.

Dirty workaround

The dirty workaround for this issue was to restart docker service with

sudo systemctl restart docker.service

After restart, Docker would operate normally and I could start my application with docker-compose without any issues. But to make it work after unexpected reboot, I’d have to create a script that would reset docker service and then trigger docker-compose deployment - kind of lame and it didn’t solve underlying problem at all.

Google & StackOverflow for the win

After googling for a little while, I’ve found a thread on StackOverflow that was pretty much describing my situation. Author solved the issue on his own and posted that, in his case, it was caused by 2 versions of Docker installed simultaneously: one through apt repo, other one through snap.

To verify that I was facing the same issue, I checked installed packages with below commands:

sudo apt list --installed | grep docker
sudo snap list | grep docker

And, indeed, each package repository had Docker installed (with different versions). Since I was using the one from apt repository, the solution was as simple as running:

sudo snap remove docker

That did the trick - no more issues with Docker after reboot!

If you’re facing a similar issue, hope it’ll save you some time!