Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post

gkzz
3 min readMay 26, 2019

--

I can’t execute docker command, “docker image pull”

Docker Installtion:

ubuntu@ip-xxx-xxx-xxx-xxx:~$ sudo apt-get update -y
ubuntu@ip-xxx-xxx-xxx-xxx:~$ sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
ubuntu@ip-xxx-xxx-xxx-xxx:~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
ubuntu@ip-xxx-xxx-xxx-xxx:~$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
ubuntu@ip-xxx-xxx-xxx-xxx:~$ sudo apt-get update -y
ubuntu@ip-xxx-xxx-xxx-xxx:~$ sudo apt-get install docker-ce docker-ce-cli containerd.io

Confrimation to install docker:

ubuntu@ip-xxx-xxx-xxx-xxx:~$ docker --version
Docker version 18.09.6, build 481bc77
ubuntu@ip-xxx-xxx-xxx-xxx:~$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:0e11c388b664df8a27a901dce21eb89f11d8292f7fca1b3e3c4321bf7897bffe

Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/

I think it works well.
I tryied to execute command, “docker image pull”…

ubuntu@ip-xxx-xxx-xxx-xxx:~$ docker image pull gihyodocker/echo:latest
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.39/images/create?fromImage=gihyodocker%2Fecho&tag=latest: dial unix /var/run/docker.sock: connect: permission denied

Oops!

I got an error message!!

The case to execute “docker run hellow world” is also same.

ubuntu@ip-xxx-xxx-xxx-xxx:~$ docker run hello-world
docker: 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.39/containers/create: dial unix /var/run/docker.sock: connect: permission denied.
See 'docker run --help'.
ubuntu@ip-xxx-xxx-xxx-xxx:~$

Docker’s documentation tells me this solution, that is only to add <YOUR_USER_NAME> to the “docker” group, something like this.

ubuntu@ip-xxx-xxx-xxx-xxx:~$ sudo usermod -aG docker ubuntu
ubuntu@ip-xxx-xxx-xxx-xxx:~$ docker run hello-world
docker: 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.39/containers/create: dial unix /var/run/docker.sock: connect: permission denied.
See 'docker run --help'.
ubuntu@ip-xxx-xxx-xxx-xxx:~$

sources;

Oh, I guess I have to exit.

ubuntu@ip-xxx-xxx-xxx-xxx:~$ exit
logout
Connection to xxx.xxx.xxx.xxx closed.
uer@localhost:~$ ssh -i ~/.ssh/<YOUR_SECRET_KEY>.pem ubuntu@xxx.xxx.xxx.xxx
ubuntu@xxx.xxx.xxx.xxx:~$ docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/

Check OS vesrion:

ubuntu@ip-xxx-xxx-xxx-xxx:~$ cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.2 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.2 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
ubuntu@ip-172-31-44-120:~$

Thank you!

I’m happy to you to follow me on medium and Twitter!

--

--

gkzz
gkzz

Written by gkzz

🇯🇵 #SoftwareDeveloper #MeijiUniv @apc_tweet Opinions are my own. #Geek #ギークハウス大倉山 #gkz https://gkzz.github.io/

No responses yet