Issue with Docker: not working correctly after server reboot

I recently came across a weird issue regarding Docker service.

Problem's description

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.

Errors

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 on boot!

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

Best Regards,
Kuba

Thanks for reading the article, I really appreciate it! Have you heard about Braintrust - the first decentralized talent network? Whether you're a freelancer looking for a job, an employer looking for hiring talents, or you just have a wide network of connections - there's something for you there!

Go check it out and register with below link (yeah - it's my referral link and it's free - no hidden costs):

Registration link