Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.

環境

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/

無事実行できた。

eversense
家族を幸せにすることで、笑顔溢れる社会をつくる。
https://eversense.co.jp/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away