2

I am trying to use Docker CLI without sudoing every command.

For context, I am new to Linux. I've used Linux on a DigitalOcean server for about 30 hours total. This is my first Linux laptop. It is on Ubuntu 22.04.

Anyway, I'm pretty sure the common solutions aren't working because they presume sudo usermod -aG docker $USER will give Docker the same permissions as my logged in user. But I still have to write sudo before commands, so giving Docker the same permissions I have (without writing sudo first) doesn't change anything.

To show my research I've visited the three following pages and a dozen more I won't list that say the same thing

cannot connect to Docker daemon socket without sudo

Allow non-root user to use some Docker commands

How can I use docker without sudo?

https://docs.docker.com/engine/install/linux-postinstall/

The summary of the advice is

sudo groupadd docker
sudo usermod -aG docker $USER
// then one of: "newgrp docker" | "reboot" | log out and back in
docker run hello-world

but when I do docker run hello-world I get

docker: Cannot connect to the Docker daemon at unix:///home/rlm/.docker/desktop/docker.sock. Is the docker daemon running?.

This tells me sudo was still necessary to run docker because sudo before the prev cmd still works.

So what do I have to do to make these steps work for me? Do I have to elevate the account I use for my laptop (Im the only user) to root so that giving Docker my permissions removes need for sudo? I don't want my typical logged in user (even if its me) to be able to run just any command without sudo in front of it. That seems bad to me.

  • "// then one of: "newgrp docker" | "reboot" | log out and back in" ... What was the output of id after doing one of these? Is docker listed as one of your groups? – muru Jun 27 '22 at 02:49
  • the output of id is: uid=1000(abc) gid=1000(pluto) groups=1000(pluto),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),122(lpadmin),134(lxd),135(sambashare),1001(docker)

    pluto is a previous account I used before changing my username. abc is my current account

    – plutownium Jun 27 '22 at 05:28
  • 1001 is unusual for Docker's gid. When you install Docker, it should set up a system group for itself with gid less than 1000. How did you install Docker? – muru Jun 27 '22 at 05:34
  • I used these instructions I believe. @muru – plutownium Jun 28 '22 at 01:01
  • There are two methods in that page, which one? Also, it says: "The docker group is created but no users are added to it" - and I took a look at the postinst file of docker-ce, which does have a command adding the docker group if it doesn't exist, so I think something went wrong with your install. Best purge the packages you have installed right now and re-install it afresh. – muru Jun 28 '22 at 01:57

0 Answers0