How To'sLinux

How To Fix Error Starting Docker Service Unit Not Found?

In this article, we’re going to share a few methods to fix the error failed to start docker service unit docker service not found. I faced this issue while trying to start the docker service.

systemctl start docker

As a result, this was the output,

Failed to start docker.service: Unit docker.service not found.

How to fix Error starting docker service Unit not found?

There are different ways to resolve this issue you can look into logs for details. Let’s get started!

1. Reinstall Docker

Most probably this error could arise due to an outdated version of Docker which you’re running on CentOS or Redhat. I followed this method of installation of docker on CentOS, the installations went well but upon starting the docker service through systemctl start docker the output resulted:

Failed to start docker.service: Unit docker.service not found.

The first thing we can do is uninstall the current or older version of docker.

sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine

Now, that we have successfully uninstalled docker from our system. Let’s add the correct docker repository.

sudo yum install -y yum-utils

After that add the repository,

sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo

As we removed the previous version of our docker and added a fresh repository for docker. Let’s install our docker-engine again using the yum package manager.

sudo yum install docker-ce docker-ce-cli containerd.io

This worked for me and the docker service started successfully.

sudo systemctl start docker
sudo systemctl status docker

2. Missing docker.socket

If the above method didn’t work for you and you’re still struggling with a similar issue Failed to start docker.service: Unit not found. then it would be worth checking docker.socket file.

Location: /usr/lib/systemd/system/docker.socket

In most cases the docker.socket file could be located at /lib/systemd/system or /etc/systemd/system.

Error Starting Docker Service

If the file doesn’t exist you can create a new one with the following content.

[Unit]
Description=Docker Socket for the API

[Socket]
ListenStream=/var/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker

[Install]
WantedBy=sockets.target

Now, save the file and restart docker to see if that resolved the issue.

systemctl daemon-reload
systemctl start docker.socket
systemctl start docker

3. Enable The docker.service

Enable docker service to see if that resolved the issue and make sure you’re not getting Error Starting Docker Service errors.

sudo systemctl enable docker.service

Error Starting Docker Service

4. Configure Docker Daemon

Using the following command, you can remove everything from /var/lib/docker using one more method.

rm -rf /var/lib/docker

You must configure the Docker daemon to utilize the overlay driver after removing everything from /var/lib/docker.

Update: /etc/docker/daemon.json

{
"graph": "/mnt/docker-data",
"storage-driver": "overlay"
}

Now, restart your docker service and make sure it’s working fine. And make sure your docker service is running on boot instead of manually starting it.

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

If you still face any difficulties or error starting docker service. Please comment down below and we will try to figure out a solution for you.

Don’t Miss:

Noor Qureshi

Experienced Founder with a demonstrated history of working in the computer software industry. Skilled in Network Security and Information Security.

Related Articles

Back to top button