Assume docker engine is installed in a similar way as offical doc.
The reason
In your running dockerd,
/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
^^^^^^^
(Marker ^^^ is added by me to point to the position within a line, it's not a part of the shell output.)
According to daemon socket option doc,
the -H fd:// means the daemon is using a file descriptor managed by systemctl. There will be no socket file /var/run/docker.sock in this case.
But docker cli will try to connect to the docker daemon via the docker.sock socket file, that's where the problem comes from.
The solution
In the case I run into, the docker daemon is brought up via systemctl as a service, you can find the service file path using systemctl command, for example, (marker ^^^ is added by me to point to the position within a line, it's not a part of the shell output)
ubuntu-linux-22-04-desktop:~$ sudo systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Active: active (running) since Fri 2023-05-19 23:59:31 CST; 55s ago
...
Then, modify that file on the line how dockerd is brought up
sudo vim /lib/systemd/system/docker.service
In the opened file, find a line starts with ExecStart=/usr/bin/dockerd
[Unit]
Description=Docker Application Container Engine
...
[Service]
Type=notify
the default is not to use systemd for cgroups because the delegate issues still
exists and systemd currently does not support the cgroup feature set required
for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
...
Modify the -H argument in dockerd command to use unix socket rather than fd, change the line to
ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock --containerd=/run/containerd/containerd.sock
Save the file (in vim, command model, zz), then reload
sudo systemctl daemon-reload
Then, restart docker daemon
sudo systemctl restart docker
After docker daemon restart finishes, you should be able to see the socket file
ll /var/run/*.sock
docker cli should work now. Try something like
docker ps
Hope will help to solve your problem.