docker.sock 权限被拒绝 [英] docker.sock permission denied

查看:53
本文介绍了docker.sock 权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试运行简单的 docker 命令时:

When I try to run simple docker commands like:

$ docker ps -a

我收到一条错误消息:

权限被拒绝.../var/run/docker.sock: 连接:权限被拒绝

Got permission denied ... /var/run/docker.sock: connect: permission denied

当我检查权限时

$ ls -al /var/run/

我看到这一行:

srw-rw---- root docker docker.sock

因此,我遵循了许多论坛的建议并将本地用户添加到 docker 组:

So, I follow an advice from many forums and add local user to docker group:

$ sudo usermod -aG docker $USER

但这无济于事.我仍然收到相同的错误消息.我该如何解决?

But it does not help. I still get the very same error message. How can I fix it?

推荐答案

对于那些不熟悉 shell 的人,命令:

For those new to the shell, the command:

$ sudo usermod -aG docker $USER

需要在你的 shell 中定义 $USER.这通常在默认情况下存在,但您可能需要在某些 shell 中将该值设置为您的登录 ID.

needs to have $USER defined in your shell. This is often there by default, but you may need to set the value to your login id in some shells.

更改用户组不会更改用户已打开的现有登录名、终端和 shell.为避免再次登录,您只需运行:

Changing the groups of a user does not change existing logins, terminals, and shells that a user has open. To avoid performing a login again, you can simply run:

$ newgrp docker

在当前 shell 中访问该组.

to get access to that group in your current shell.

完成此操作后,用户实际上拥有服务器上的 root 访问权限,因此仅对具有不受限制的 sudo 访问权限的用户执行此操作.

Once you have done this, the user effectively has root access on the server, so only do this for users that are trusted with unrestricted sudo access.

这篇关于docker.sock 权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆