Cannot use Docker bash command without sudo

I have two issues but let’s start with the first one. I cannot use Docker commands without sudo.

For instance if I enter “docker ps” I get nothing, but if I enter “sudo docker ps” then I get a list of running containers.

I have added myself to the “docker” group and given myself the right permissions…

pblanton@Kubuntu-OneOfTen:~$ groups pblanton
pblanton : pblanton adm cdrom sudo dip www-data plugdev lpadmin lxd sambashare docker

And tried everything else I can find online, all to no avail.

The second issue is that Docker Desktop doesn’t show any containers, running or otherwise, on my machine when I run it. I suspect that’s because the Docker Desktop app isn’t running as a super-user.

I finally found a solution to being able to run Docker without Sudo.

After installing Docker and the Docker Desktop on Ubuntu, I can run Docker commands without sudo until I reboot. After that I must use sudo.

Using sudo to build my containers, results in them being stored in a different location than Docker Desktop is aware of, unless you run Docker Desktop under sudo as well.

The answer seems to be …

$ docker context use default

Which solves the problem of being able to access the Docker daemon as yourself AND results in the images you build being visible in Docker Desktop. I haven’t rebooted yet since doing that, but as I have work to do I won’t reboot until EOD.

Do you need two Docker Daemons at the same time? If you want to use Docker Desktop, I don’t recommend to install Docker Community Edition as well. They will have two different contexts and somehow I don’t think that the default is actually owned by Docker Desktop. It is usually Docker Community Edition, but I can be wrong, since I don’t have Desktop on my Linux now. When you install Docker Community Edition it will use a unix socket to communicate with the Docker daemon. That socket is owned by “root” and it is in the “docker” group. This is why you either need to use “sudo” or you need to be in the “docker” group as well.

In case of Docker Desktop it runs a virtual machine, so the socket of the Docker deamon is in the VM too. I don’t remember if it uses a local unix socket too or a TCP socket, but that socket can be handled differently.

If you want to make sure you always use the right Docker, remove the one that you don’t actually need. I guess it is Docker Community Edition.

1 Like

When I installed Docker Desktop, it came without the docker service. Windows and Mac got both of them packaged into one, but the Linux version needed the service to be installed first, then the Desktop installed second.

If that’s changed, then that would explain my conundrum, as I am now doing it wrong - based on old facts.

I just looked at the docs and the old mention that I remember, about having to install the Docker service first is no longer there, but I did notice this…

“When Docker Desktop starts, it creates a dedicated context that the Docker CLI can use as a target and sets it as the current context in use. This is to avoid a clash with a local Docker Engine that may be running on the Linux host and using the default context. On shutdown, Docker Desktop resets the current context to the previous one.”

which explains what I am seeing.

When did you installed Docker Desktop first? As far as I know, it always ran a virtual machine. This is what Docker Desktop is. This is how Docker tries to give you the same experience on each platform. I think I installed it while it was beta and it ran a virtual machine.

Current documentation:

System requirements:link:

To install Docker Desktop successfully, your Linux host must meet the following requirements:

  • 64-bit kernel and CPU support for virtualization.
  • KVM virtualization support. Follow the KVM virtualization support instructions to check if the KVM kernel modules are enabled and how to provide access to the kvm device.
  • QEMU must be version 5.2 or newer. We recommend upgrading to the latest version.


In the meantime, you edited your comment, but I leave the quote here :slight_smile:

Thanks for your help!

On this machine the first install of Docker was about two months ago and I did follow instructions that said I needed to install the Docker engine first, but I cannot seem to find that documentation again. :frowning:

The current documentation here (Install Docker Desktop on Linux | Docker Documentation) under “Differences between Docker Desktop for Linux and Docker Engine”, explain everything I’ve been seeing. I blame myself for maybe mis-interpreting something I read wrong.

I just removed the Docker Engine from my machine and DockerDesktop still works fine. I haven’t rebooted yet, but I expect my Docker installation will now survive a reboot.

Thanks again for helping me to clarify what’s going on!! :100:

Then I am pretty sure it was a misunderstanding or a temporary mistake in the documentation. No problem, it happens. I am glad everything works :slight_smile:

1 Like