Unable to make docker run without sudo

I’m running Linux Mint 21.2 Victoria.
First I did the post installation steps as per the docs. It didn’t work.
when I run docker ps. It gives this error.

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

Then I stumbled on this post. which is same as the docs, except when all steps don’t work it just says to configure daemon.json correctly. Here’s my daemon.json

{
  "storage-driver": "btrfs"
}

I did all the things and it still gave the same error. Here’s additional Info
output of docker context ls:

NAME              DESCRIPTION                               DOCKER ENDPOINT                                   ERROR
default           Current DOCKER_HOST based configuration   unix:///var/run/docker.sock                       
desktop-linux *   Docker Desktop                            unix:///home/ubuntu/.docker/desktop/docker.sock   

output of sudo docker context ls:

NAME        DESCRIPTION                               DOCKER ENDPOINT               ERROR
default *   Current DOCKER_HOST based configuration   unix:///var/run/docker.sock   

edit: I was able to solve the issue by switch docker context to default. But what this docker endpoint running by name desktop-linux. Why is it running? How to terminate it?

Before the “post” install you should do the regular install. How was that done?

You write in “Open Source” forum, but there is a desktop in your path, hinting to “Docker Desktop”, which is a different product than the open source engine (“Docker CE” community edition).

The docs are for docker-ce, but your context is set to docker-linux (=Docker Desktop)

What you did applies to docker-ce. Just switch back to the default context and you should be able to use the docker command without sudo for docker-ce: docker context use default

Note: people that install docker-ce and docker desktop often struggle with “surprises” as they tend to forget what they did in which context. You might want to remove either docker-ce or docker desktop.

2 Likes

I think everything else was answered, except

As it is suggested in previous posts, you have Docker Desktop installed. Why it is running? Because you started it :slight_smile: I think your real question is why the other one is running. If you didn’t install it intentionally, you probably misunderstood the requirements and installed docker engine as well, when all you needed to install the docker client, which is as far as I know is automatically installed by docker desktop. So all you need is to add the required apt repository and let Docker Desktop install its requirements. If you don’t need the engine, which is independent from Docker Desktop, you can delete the “docker-ce” package.

Yeah, the Docker Desktop was causing the issue. If the docker context is set to docker desktop, I can’t use docker without sudo.It will only work, if I change the context. However, in both cases docker desktop is not working. It just shows the loading spinner and be there. What’s worse is whenever I open the Docker Desktop, it changes the docker context to Docker Desktop and breaks the post installation step.
Tbh, I just wanted Docker Desktop just for docker init command. I’m still new to Docker and sheer amount of things I need to know to create docker-compose and DockerFile overwhelms me.

I see. So the problem is that Docker Desktop didn’t work. You could open a topic on this forum in Docker Destkop for Linux category or open an issue on GitHub

If you can’t use Docker Desktop, you can learn about simple compose files and Dockerfile from my tutorials too

https://learn-docker.it-sziget.hu/en/latest/

2 Likes