Install Script fail with "A dependency job for docker.service failed"
This error shows when running the install script in a Digital Ocean droplet
This is the error "Dependency failed for docker.service - Docker Application Container Engine", indicating that the Docker service cannot start due to dependency issues. Here's how to resolve it:
Check Docker Service Status
Use the command systemctl status docker to view the Docker service status. If it's not running, attempt to start it with sudo systemctl start docker.
Restart Docker Service
If Docker is installed and running but still encountering errors, execute sudo systemctl restart docker to restart the service.
Clear Docker Cache
A corrupted cache might cause problems. Run docker system prune --all --force --volumes to clean up unused images, containers, and volumes.
Update Docker Version
Older versions may have bugs. Update according to your system and package manager:
- Ubuntu/Debian:
sudo apt-get updatesudo apt-get upgrade docker-ce
- CentOS/RHEL:
sudo yum update docker-ce
Reinstall Docker
If the above methods are ineffective, uninstall and reinstall:
- Ubuntu/Debian:
sudo apt-get purge docker-cesudo rm -rf /var/lib/docker- Reinstall following official documentation.
- CentOS/RHEL:
sudo yum remove docker-cesudo rm -rf /var/lib/docker- Reinstall following official documentation.
Check Dependent Services
Docker depends on services like networking and containerd. Ensure they are running properly:
- Check status:
sudo systemctl status containerdsudo systemctl status networking
- If not running, restart them:
sudo systemctl restart containerdsudo systemctl restart networking
Check System Resources and Permissions
- Check Resources: Use commands like
free -h,df -h,topto check memory, disk space, and CPU usage. If resources are insufficient, free up or add resources. - Check Permissions: Inspect permissions of Docker-related directories, e.g.,
ls -ld /var/lib/docker,ls -l /etc/docker. Fix incorrect permissions with commands likesudo chown -R root:docker /var/lib/dockerandsudo chmod -R 755 /var/lib/docker.