当前位置:   article > 正文

Failed to start docker.service: Unit not found.

failed to start docker.service: unit not found.

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

After installing the Docker when I executed the following command -

systemctl start docker 

I immediately faced the following error on my CentOS machine - 

Failed to start docker.service: Unit not found.

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

Job for docker.socket failed. See "systemctl status docker.socket" and "journalctl -xe" for details. 

Here are the different ways in which I tried to fix the issue -

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 CentOS 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 manage

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

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 -

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 -

sudo systemctl start docker 

5. Verify the docker installation

You can now verify the docker installation by running the following docker command -

sudo docker run hello-world

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. [Socket]
  5. ListenStream=/var/run/docker.sock
  6. SocketMode=0660
  7. SocketUser=root
  8. SocketGroup=docker
  9. [Install]
  10. 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

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/system.

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

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 -

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 -

  1. {
  2. "graph": "/mnt/docker-data",
  3. "storage-driver": "overlay"
  4. }

(*Note - If the daemon.json does not exist then you can create the file manually)

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

Finally, we can run

sudo systemctl daemon-reload

and retry

  1. sudo systemctl start docker
  2. sudo journalctl -u docker

Reference :

1.How to fix Error starting docker service Unit not found? | Jhooq

2.Unable to start Docker service with error "Failed to start docker.service: Unit not found." - Stack Overflow

3.rhel - Error starting docker service: Unit not found - Unix & Linux Stack Exchange 

4.Cannot start docker daemon in CentOS7 - Stack Overflow

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/973716
推荐阅读
相关标签
  

闽ICP备14008679号