0

I try to execute docker run hello-world on a debian bullseye machine where I do not have root user rights, but where I can use sudo.

I installed docker (v19.03.13) with sudo according to the docker documentation. docker can be started using sudo systemctl start docker and according to sudo systemctl status docker the service is running as expected. As well sudo systemctl status docker.socket looks normal.

I found a docker.sock file at /var/run/.

Now, when try to run docker run hello-world (no sudo!) I get an error message:

docker: Cannot connect to the Docker daemon at unix:///home/<myuser>/.docker/run/docker.sock. Is the docker daemon running?.

So as it seems, the docker service is looking in the wrong directory for docker.sock.

The following things I tried already, but didn't work:

  • sudo systemctl stop/start/restart docker(standard answer I found in discussions about this problem)
  • added my user to docker group: sudo usermod -aG docker $USER. Command less /etc/group | grep docker yields docker:x:999:myUserName
  • ls -la /var/run/docker.sock--> srw-rw---- 1 root docker 0 Jul 17 17:48 /var/run/docker.sock (suggested by https://unix.stackexchange.com/a/279785/335075)
  • unset DOCKER_HOST (e.g. https://stackoverflow.com/a/69674630/1552080).
  • sudo mount -t cgroup -o none,name=systemd cgroup /sys/fs/cgroup/system (this worked once, but not a second time after I logged out an in again)

What I can do is run sudo docker run hello-world.

2 Answers 2

1

It sounds like you have somehow setup an alternative docker context for your user. Perhapse you were experimenting with installing docker another way or have inadvertatly typed something.

You can check this with

$ docker context ls
NAME        DESCRIPTION                               DOCKER ENDPOINT               ERROR
default *  

Docker documentation includes instructions for both creating a new context and selecting a context:

$ docker context create docker-test --docker host=tcp://docker:2375
docker-test
Successfully created context "docker-test"
$ docker context use docker-test
docker-test
Current context is now "docker-test"
1
  • I did a docker context use default. Then I still got the "daemon running" error. It works if I execute unset DOCKER_HOST (without sudo). Maybe I always did unset... with sudo when writing my post. Commented Jul 18, 2024 at 10:53
0

Finally, I found the root cause to this problem. I found an entry in .bashrc explicitly setting the path for docker.sock

Found in .bashrc:

# Docker rootless configuration
export XDG_RUNTIME_DIR=/home/<myusername>/.docker/run
export PATH=$PATH:/sbin
export DOCKER_HOST=unix:///home/<myusername>/.docker/run/docker.sock

Changed to

# Docker rootless configuration
export XDG_RUNTIME_DIR=/var/run
export PATH=$PATH:/sbin
export DOCKER_HOST=unix:///var/run/docker.sock

I don't know if this causes other problems, but at first glance it spares me from unset DOCKER_HOST at logging in.

1
  • Firstly, not all users' home directories are in /home; root and all the service owners are obvious examples, but even humans can have home directories elsewhere. Secondly, using <angle brackets> to indicate substitutions in code is awkward, especially markdown code literal blocks; prefer using predefined variables such as $HOME or $USER instead: XDG_RUNTIME_DIR=$HOME/.docker/run and DOCKER_HOST=unix://$HOME/.docker/run/docker.sock. Commented Jul 20, 2024 at 2:40

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.