3

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

4
  • 1
    Does the answer in this question help you? askubuntu.com/q/477551/117753 Until recently, these were the steps that you need to do to have use Docker without sudo: docs.docker.com/engine/install/linux-postinstall Feb 22, 2021 at 22:11
  • The post-install steps are simply adding the current user to the docker group. And as mentioned in the question, I'm already a member of that group. Running docker-rootless.sh yields [rootlesskit:parent] error: failed to setup UID/GID map: newuidmap 25367 [0 1000 1 1 100000 65536] failed: newuidmap: Target process 25367 is owned by a different user: uid:1000 pw_uid:1000 st_uid:1000, gid:999 pw_gid:1000 st_gid:999 Feb 22, 2021 at 22:21
  • You may need to sign out and back in to get it to work
    – ti7
    Feb 22, 2021 at 22:24
  • 1
    I've rebooted since adding myself to the docker group Feb 22, 2021 at 22:30

2 Answers 2

4

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.

1
  • 1
    To add to this. I was setting the variable as a remnant of non-root config in my .zshrc/bashrc file. Apr 14, 2022 at 21:11
1

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.

UPDATE: 12/2022 Recently had to do this on Ubuntu 22.04 LTS and ran into the login shell persisting the previous group.

Since the UI manages the login shell, a restart is either required, or you need to replace the process with exec. You can work around this issue, until you restart, by replacing your current shell process: (use $0 instead, if $SHELL doesn't match your preferred shell)

exec sudo -u $USER -E $SHELL
5
  • 👎 Even after restarting the daemon, the error persists. And $SUDO_USER isn't a variable Feb 22, 2021 at 22:30
  • SUDO_USER is a variable... after you've used sudo to change users in the current session. However, because shell expansions take place before sudo runs, @git_driver probably meant to just suggest $USER there. Feb 22, 2021 at 22:31
  • sudo echo $SUDO_USER outputs an empty string Feb 22, 2021 at 22:33
  • I doubt this particular case matters much if SUDO_USER exists (you won't need it for the normal user run condition of your question), but shells will expand $foo in sudo echo $foo before sudo executes
    – ti7
    Feb 22, 2021 at 22:42
  • Whichever variable is being used, does it really matter since my user is already part of the group AS MENTIONED IN THE QUESTION? Feb 22, 2021 at 22:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.