Can't run docker as a normal user

Viewed 874

I can't run docker commands as my own user. But I know that the service is running because I can run commands as sudo:

$ docker ps
Cannot connect to the Docker daemon at unix:///run/user/1000/docker.sock. Is the docker daemon running?
$ sudo docker ps
CONTAINER ID   IMAGE             COMMAND                  CREATED         STATUS                 PORTS                    NAMES
(snip)         (snip)            (snip)                   13 days ago     Up 2 hours (healthy)   9000/tcp                 (snip)

I am successfully running a few containers, and they each work, but I have another not listed in that I need to run as my own user.

I am part of the docker group:

$ groups
docker www-data video tim

I'm not sure what else to check. I do have this:

$ echo $DOCKER_HOST
unix:///run/user/1000/docker.sock

Also:

$ uname -r
5.4.0-65-generic
$ docker --version
Docker version 19.03.6, build 369ce74a3c

This is on Ubuntu 18.04.5 LTS

2 Answers

As you followed all the post installation steps correctlly, as far as I can tell, my best guess is that has to do with the DOCKER_HOST environment variable.

Does it help if you unset DOCKER_HOST? (Perhaps you need to log out, so it has an effect.)

On my system, docker ps works with sudo, but once I set DOCKER_HOST=unix:///run/user/1000/docker.sock, I get the same error as you.

For some background, here is a question about the DOCKER_HOST variable. In essence, that variable should normally not be set.

Return to the default sock path (unix:///var/run/docker.sock), by unsetting DOCKER_HOST and removing an errant config files:

unset DOCKER_HOST rm -r ~/.docker

The Docker Daemon must be restarted after creating the “docker” group: sudo services docker restart

Then, ensure you add your current user to the group: sudo usermod -a -G docker $USER

This will ensure your user has access to the socket file.

Related