Socket: connect: permission denied

I’m trying to build environmet for my project.
It’s the first time I’m using Docker, I did everything according to the documentation provided…

The hello world image test works with no problem, my docker runs according to my terminal.

But when I try to enter this in the terminal

docker buil buildenv -t osproject-buildenv

it gives me the following error:

docker build buildenv -t osproject-buildenv
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&shmsize=0&t=osproject-buildenv&target=&ulimits=null&version=1": dial unix /var/run/docker.sock: connect: permission denied

I’m using Linux Debian.

Could someone help me to find out what’s the problem and how to fix it?

docker run and docker build would use the same socket. Are you sure you did not run docker run as root and then docker build as a non-root user? The socket name does not seem like the socket of Docker Desktop. I don’t have Docker Desktop for Linux currently, so I can’t check it.

Thanks a lot! Due to your answer, I just noticed I was doing it without accesing as a root user…
I applied the same command as a root user and now it works.