41
24

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

「Got permission denied while trying to connect to the Docker daemon socket」への対応

Posted at

環境

OS

$ cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)

docker

公式の通りdocker-ceをインストール

概要

yumにてdockerをインストール後、dockerコマンドを実行するとタイトルにあるよう下記のエラーが発生した。

$ docker run hello-world
Using default tag: 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.26/images/create?fromImage=python&tag=latest: dial unix /var/run/docker.sock: connect: permission denied

どうやらdockerコマンドはデフォルトではroot権限で無いと動かないらしい。(一般ユーザでは動かせない)
たしかにsockファイルに権限が無かった。

$ ll /var/run/docker.sock
srw-rw---- 1 root docker 0 Apr 10 02:18 /var/run/docker.sock

行った対応

公式の言うとおり、一般ユーザを「docker」グループに追加する。

$ grep -i docker /etc/group
docker:x:990:

$ sudo gpasswd -a username docker
Adding user username to group docker

$ grep -i docker /etc/group
docker:x:990:username

グループに入ったことを確認した後、一旦ログアウトを行い、再度ログインする。

そして、もう一度 docker run を実施してみる

$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
Digest: sha256:97ce6fa4b6cdc0790cda65fe7290b74cfebd9fa0c9b8c38e979330d547d22ce1
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://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

無事実行できた。

41
24
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
41
24

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?