Not able to access docker command with non-sudo user?

58 Views Asked by At

Why I am getting this error when executing docker version with non-sudo user. I have installed docker using Script

Output with non-sudo user

docker version
Client: Docker Engine - Community
 Version:           24.0.5
 API version:       1.43
 Go version:        go1.20.6
 Git commit:        ced0996
 Built:             Fri Jul 21 20:35:18 2023
 OS/Arch:           linux/amd64
 Context:           desktop-linux
Cannot connect to the Docker daemon at unix:///home/cttc/.docker/desktop/docker.sock. Is the docker daemon running?

Output with sudo user

sudo docker version
Client: Docker Engine - Community
 Version:           24.0.5
 API version:       1.43
 Go version:        go1.20.6
 Git commit:        ced0996
 Built:             Fri Jul 21 20:35:18 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          24.0.5
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.6
  Git commit:       a61e2b4
  Built:            Fri Jul 21 20:35:18 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.22
  GitCommit:        8165feabfdfe38c65b599c4993d227328c231fca
 runc:
  Version:          1.1.8
  GitCommit:        v1.1.8-0-g82f18fe
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

My user is part of a docker group. Previously, there is an installation of docker desktop but I have uninstalled it.

1

There are 1 best solutions below

0
CloudWatcher On BEST ANSWER

Since my suspicions in the comments were confirmed, I am here writing it up again.

The docker version command put out the context for the non-root user as
Context: desktop-linux
and for the root user as
Context: default
This discrepancy put me on the right path. Using docker context show intuitively shows the current docker context in which the program works. These contexts were confirmed to be different for the different users.

Docker contexts can be switched with docker context use <context name>, so here default or desktop-linux.