0% found this document useful (0 votes)
20 views

How To Fix Error Starting Docker Service Unit Not Found - Jhooq

Uploaded by

gharbiabdo1981
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

How To Fix Error Starting Docker Service Unit Not Found - Jhooq

Uploaded by

gharbiabdo1981
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Home Ansible Kubernetes Terraform YouTube

How to fix Error starting docker service Unit


not found?
Jul 24, 2021 · 4 min read

· Last Modified : Jul 24, 2021 Share on: Author : Rahul Wagh

In this blog post, we will look at the different ways to fix the Error starting docker service
Unit not found.

I faced this issue while I was trying to set up Kubernetes cluster on CentOS 8. As Kubernetes is
a container orchestration tool and it is used for managing container images, so I had to install
Docker before installing the Kubernetes cluster.

But after installing the Docker when I executed the following command -

BASH
1 systemctl start docker

I immediately faced the following error on my CentOS machine -

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

Incase if you are working on RedHat then you might face this error message -

1 Job for docker.socket failed. See "systemctl status docker.socket" and "journalctl -x

Here are the different ways in which I tried to fix the issue -
Table of Content Home Ansible Kubernetes Terraform YouTube

1. Re-install the latest version of docker


2. Add missing docker.socket
3. Enable docker.service
4. Configure docker daemon to use overlay storage drive

1. Re-install the latest version of docker

There is a very high possibility that the version of docker which you running either onto your C
entOS or RedHat machine is not supported and this is what happened with me.

I just randomly installed docker onto my CentOS machine. Installation went pretty smooth but
when I tried starting docker systemctl start docker I noticed it can not find the docker.service
.

After some time spending time on google and searching solutions on the forums I decided to
remove all the docker container and do a fresh installation of the docker. But this time I
referred to the official guide of docker for installation.

And here are the steps which I followed after that -

1. Uninstall old version of docker -

The first important step is to remove the previous docker installation and all the docker
components such as - docker-engine, docker-client, docker-common, docker-logrotate etc.

Here is the command for removal -

1 sudo yum remove docker \


2 docker-client \
3 docker-client-latest \
4 docker-common \
5 docker-latest \
6 docker-latest-logrotate \
7 docker-logrotate \
8 docker-engine
2. Add docker repository to Yum package
Home manage
Ansible Kubernetes Terraform YouTube

After removing the old version of docker you must add the latest and correct docker
repository to your yum package manager.

1 sudo yum install -y yum-utils

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

3. Install Docker engine

Now we have removed the old version of docker as well as the added latest version of the
Docker repository to yum package manager.

Now its time for installing the docker -

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

4. Start Docker service

After installing the docker in the previous step let us start the docker service -

1 sudo systemctl start docker

5. Verify the docker installation

You can now verify the docker installation by running the following docker command -
1 sudo docker run hello-world Home Ansible Kubernetes Terraform YouTube

2. Add missing docker.socket

If you have done the installation of docker as described in the Step-1 but still struggling with
the issue Failed to start docker.service: Unit not found. then I would recommend checking
the docker.socket file.

You can find this file at location - /usr/lib/systemd/system/docker.socket

If the file docker.socket is missing then you can create the file with the following content -

1 [Unit]
2 Description=Docker Socket for the API
3 PartOf=docker.service
4
5 [Socket]
6 ListenStream=/var/run/docker.sock
7 SocketMode=0660
8 SocketUser=root
9 SocketGroup=docker
10
11 [Install]
12 WantedBy=sockets.target

Create and save the file, after that run the following command -

1 systemctl daemon-reload
2 systemctl start docker.socket
3 systemctl start docker

You docker service should start after this.


3. Enable docker.service
Home Ansible Kubernetes Terraform YouTube

This solution is a little trivial because at first glance you will notice everything (docker
installtion, docker.socket) which you did is correct but still you are getting the error Failed to
start docker.service: Unit not found.

In such a cases the docker.socket file should be either at /lib/systemd/system or /etc/systemd/s


ystem.

Goto those file locations and enable the docker.service using the following command -

1 sudo systemctl enable docker.service

4. Configure docker daemon to use overlay storage


drive

There is one more approach where you need to delete everything from /var/lib/docker using
the following command -

BASH
1 rm -rf /var/lib/docker

After removing everything from the /var/lib/docker you need to set docker daemon to use
overlay driver.

You need to update the flag inside /etc/docker/daemon.json. Here is the content of the flag -

BASH
1 {
2 "graph": "/mnt/docker-data",
3 "storage-driver": "overlay"
4 }
(*Note - If the daemon.json does not exist
Home then you can create
Ansible the file manually)
Kubernetes Terraform YouTube

Now you can restart the docker service and it should work fine.

Also if you want the docker service to start at the boot time instead of manually then you can
set the following -

1 sudo systemctl enable docker.service


2 sudo systemctl enable containerd.service

Reference :- Here are some references which I took to consolidate all possible solutions to fix
the issue

1. Stackoverflow - Cannot start docker daemon in CentOS7


2. Unix Stackexchange - Error starting docker service: Unit not found

0 Comments - powered by utteranc.es

Write Preview

Sign in to comment

Styling with Markdown is supported Sign in with GitHub

Posts in this series

(docker run -d) Why Does a Docker Container Stop Automatically?


Attach and detach from Docker's process?
How I Change Name of My Docker Repository and Rename Images?
How to set-up Cron Jobs in Docker Containers?
4 Ways to copy file from localhost to docker container
Multiple commands execution in Docker Compose?
How to push Docker Images to AWS ECR(Elastic Container registry)?

You might also like