0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

"Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json": dial unix /var/run/docker.sock: connect: permission denied"エラーを解決

Last updated at Posted at 2022-09-28

最近VagrantやDockerを使った学習をしています!私の業務上、両スキル必須ですのでどちらも学習が欠かせません。

1.エラー発生

vagrantを立ち上げて、ssh接続を実施した後、dockerコマンドを打つもエラーが発生

[vagrant@localhost ~]$ docker ps
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json": dial unix /var/run/docker.sock: connect: permission denied

これは明らかな権限エラーっぽい。

2.解決

要するに、unix:///var/run/docker.sockの実行権限がないので、実行グループに割り当てたらいいですね。

[vagrant@localhost ~]$sudo chown $(whoami) ///var/run/docker.sock

これで解決します。
しかし、これではvagrantを再起動するたびにリセットされてしまいます。そのたびに上記コマンドを打つのは面倒くさいですよね。
そこで、vagrantを起動させるたびにコマンドを自動で実行してくれるように.bashrcファイルに記載しましょう。

/home/vagrant/.bashrc
#一番下に記載
sudo chown $(whoami) ///var/run/docker.sock

一度sshからexitしましょう。そしてもう一度ssh接続してdockerコマンドを打ってみると...

[vagrant@localhost ~]$ docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

無事にできました。

3.最後に

docker関係のエラーは、dockerがストップしている、権限不足、イメージ・コンテナが存在しない等が多いです。エラーが出たときは最初に確認してみましょう。

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?