赞
踩
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
4. Configure docker daemon to use overlay storage drive
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 -
- sudo yum remove docker \
- docker-client \
- docker-client-latest \
- docker-common \
- docker-latest \
- docker-latest-logrotate \
- docker-logrotate \
- 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
- sudo yum-config-manager \
- --add-repo \
- 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
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 -
- [Unit]
- Description=Docker Socket for the API
- PartOf=docker.service
-
- [Socket]
- ListenStream=/var/run/docker.sock
- SocketMode=0660
- SocketUser=root
- SocketGroup=docker
-
- [Install]
- WantedBy=sockets.target
Create and save the file, after that run the following command -
- systemctl daemon-reload
- systemctl start docker.socket
- systemctl start docker
You docker service should start after this.
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
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 -
- {
- "graph": "/mnt/docker-data",
- "storage-driver": "overlay"
- }
(*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 -
- sudo systemctl enable docker.service
- sudo systemctl enable containerd.service
Finally, we can run
sudo systemctl daemon-reload
and retry
- sudo systemctl start docker
- sudo journalctl -u docker
Reference :
1.How to fix Error starting docker service Unit not found? | Jhooq
3.rhel - Error starting docker service: Unit not found - Unix & Linux Stack Exchange
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。