Docker daemon failed

Hi my local environment didn’t show up when I ran my Portainer GUI and i ended up tweaking some settings in my Ubuntu server which seemingly corrupted my docker setup and now my docker can’t start anymore. Maybe somebody could help before I give up! I’m still a beginner

My current status:

docker ps

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

systemctl status docker

× docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Mon 2024-03-04 03:07:12 UTC; 11h ago
TriggeredBy: ○ docker.socket
       Docs: https://docs.docker.com
    Process: 881 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock (code=exited, status=1/FAILURE)
   Main PID: 881 (code=exited, status=1/FAILURE)
        CPU: 412ms



Mar 04 03:07:12 linodeusercontent.com systemd[1]: docker.service: Failed to schedule restart job: Unit docker.socket has a bad unit file setting.
Mar 04 03:07:12 .linodeusercontent.com systemd[1]: docker.service: Failed with result 'exit-code'.

Anybody know where i should go from here?

What settings? That socket is created automatically when you start the docker.socket systemd unit, but you have to stop the docker service as well. If you changed the owner or permissions or the file is corrupted, you can delete and recreate it that way. Does it work with sudo docker info ?

I’m assuming that I corrupted the docker.socket file by running vi and inserting the wrong parameters and don’t know how to restore them to default however the result for ‘sudo docker info is below;

sudo docker info

Client:
Version: 24.0.5
Context: default
Debug Mode: false

Server:
ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
errors pretty printing info

I edited your messages. Please, format your post next time according to the following guide: How to format your forum posts
In short: please, use </> button to share codes, terminal outputs, error messages or anything that can contain special characters which would be interpreted by the MarkDown filter. Use the preview feature to make sure your text is formatted as you would expect it and check your post after you have sent it so you can still fix it.

Example code block:

```
echo "I am a code."
echo "An athletic one, and I wanna run."
```

Asking you for running docker info would not have been necessary as you shared the output of the service status. It shows that the socket has bad unit file setting. So you probably edited that. If you share the content of the file you edited, I can try to tell you what is wrong. By the way editing systemd unit files using a text editor is not recommended. It is better using the systemctl edit command whichc reates an override file.

For now, please, show the output of the following command:

cat /etc/systemd/system/sockets.target.wants/docker.socket

This is how mine looks like:

[Unit]
Description=Docker Socket for the API

[Socket]
# If /var/run is not implemented as a symlink to /run, you may need to
# specify ListenStream=/var/run/docker.sock instead.
ListenStream=/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker

[Install]
WantedBy=sockets.target
1 Like

The output for the command:

cat /etc/systemd/system/sockets.target.wants/docker.socket

Looks like this:

[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

It seems there is a missing slash character at the begining of the value of ListenStream. If you really want the value to be /var/run/docker.sock, fix it this way:

ListenStream=/var/run/docker.sock

And run

systemctl start docker.socket

but I believe starting docker should be enogh

systemctl start docker

Updated docker.socket file


[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


systemctl start docker result:


Failed to start docker.service: Unit docker.socket has a bad unit file setting.
See system logs and 'systemctl status docker.service' for details.

systemctl status docker.service result:

× docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Mon 2024-03-04 03:07:12 UTC; 1 day 10h ago
TriggeredBy: ○ docker.socket
       Docs: https://docs.docker.com
    Process: 881 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock (code=exited, status=1/FAILURE)
   Main PID: 881 (code=exited, status=1/FAILURE)
        CPU: 412ms

However i ran systemctl status docker.socket and it gave me this result:

Warning: The unit file, source configuration file or drop-ins of docker.socket changed on disk. Run 'systemctl daemon-reload' to reload units.
○ docker.socket - Docker Socket for the API
     Loaded: bad-setting (Reason: Unit docker.socket has a bad unit file setting.)
     Active: inactive (dead)
   Triggers: ● docker.service

Ran systemctl daemon-reload and tried systemctl status docker.socket once again and now i have the following result:

○ docker.socket - Docker Socket for the API
     Loaded: bad-setting (Reason: Unit docker.socket has a bad unit file setting.)
     Active: inactive (dead)
   Triggers: ● docker.service

Mar 05 18:19 linodeusercontent.com systemd[1]: /lib/systemd/system/docker.socket:6: Failed to parse address value in 'var/run/docker.sock', ignoring: Invalid argument
Mar 05 18:19 linodeusercontent.com systemd[1]: docker.socket: Unit has no Listen setting (ListenStream=, ListenDatagram=, ListenFIFO=, ...). Refusing.

Something is not right here. Now even your error message contains the path with the missing slash character. The file I shared was syntactically correct, but now it is as if the filename become a keyname in the socket unit file.

Just for clarity’s sake…

I edited the docker.socket file by just running vi docker.socket directly from the root directory but when i followed the path specified in the error message,

i ran cat docker.socket and this was the result:

[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

The slash character is missing as you can see from the result so is it possible to have another path or 2 different directories which contain the docker.socket file?
NB: I am logged into the server as a root#

Simply put when i run cat docker.socket from the the root directory i get parameters with the slash character that was missing before but if i run the the same command from the path specified in the the error message i get parameters without the slash character.

Normaly that would be the original file and the one I suggested editing is a symbolic link to that:

/etc/systemd/system/sockets.target.wants/docker.socket

Make sure it is true:

ls -la /etc/systemd/system/sockets.target.wants/docker.socket

You can try to stop the docker socket and also disable it, then edit the original file, reenable it and start docker again after reloading the systemd daemon

systemctl stop docker
systemctl stop docker.socket
systemctl disable docker.socket
# Edit the file at this point
systemctl daemon-reload
systemctl enable docker.socket
systemctl start docker.socket
systemctl start docker

You can also check the file before each step to see when it i changed if it will be changed again.

it worked Sir , thank you very much for your help