to be
a problem slover

普通用户docker run报错socket permission denied解决办法

问题描述

使用普通用户运行docker run的时候,如果该用户不在用户组docker内会有如下报错

$ 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.40/containers/create: dial unix /var/run/docker.sock: connect: permission denied.
See 'docker run --help'.

解决办法

step1: 将用户加入 docker 用户组

使用usermod命令将当前用户加入 docker 用户组

sudo usermod -aG docker $USER

命令说明

  • usermod – 用来改变用户组、权限、家目录、密码之类的,和用户相关的一些设置
  • a – a for append, 将用户添加到补充组。仅与-G 选项一起使用
  • G – 补充用户组 (-g 为主要用户组)
  • docker – 用户组名
  • $USER – 当前用户名环境变量

step2: 刷新用户组

使用su - $USER刷新用户组

然后使用id命令查看用户组,用户组中应该包含了docker

step3: 验证问题

再次运行docker run hello-world测试,问题应该得到解决了

参考资料

What does ‘sudo usermod -a -G group \$USER’ do on Linux?

Reload a Linux user’s group assignments without logging out

赞(3) 打赏
欢迎转载,注明出处:刘世明的博客 » 普通用户docker run报错socket permission denied解决办法

评论 3

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #1

    Your article helped me a lot, is there any more related content? Thanks! https://www.binance.com/join?ref=IXBIAFVY

    Binance开户2个月前 (03-16)回复
  2. #2

    Thanks for sharing. I read many of your blog posts, cool, your blog is very good. https://www.binance.info/register?ref=QCGZMHR6

    Binance推荐码1个月前 (04-12)回复
  3. #3

    I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.

    Binance推荐奖金1个月前 (04-15)回复

觉得文章有用就打赏一下作者

支付宝扫一扫打赏

微信扫一扫打赏