如何修复Docker:获得权限被拒绝的问题 [英] How to fix docker: Got permission denied issue
本文介绍了如何修复Docker:获得权限被拒绝的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在装有Ubuntu OS的计算机上安装了Docker。然后安装docker之后,当我运行
I installed Docker in my machine where I have Ubuntu OS. After than I installed docker, when I run
sudo docker run hello-world
没关系,但我想隐藏 sudo
一词以使命令更短。
All it's ok, but I want to hide the word sudo
to make more short the command.
如果我写的命令没有单词 sudo
If I write the command without the word sudo
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.35/containers/create: dial unix /var/run/docker.sock: connect: permission denied.See 'docker run --help'.
当我尝试制作时也是如此
It's happened the same when I try to make
docker-compose up
我该如何解决
推荐答案
如果要以非root用户身份运行docker,则需要将其添加到docker组。
If you want to run docker as non-root user then you need to add it to the docker group.
- 创建不存在的docker组
$ sudo groupadd docker
- 将您的用户添加到docker组。
$ sudo usermod -aG docker $USER
- 运行以下命令或注销并再次登录并运行(不起作用,您可能需要先重新启动计算机)
$ newgrp docker
- 检查是否泊坞窗可以运行没有root用户
$ docker run hello-world
如果仍然出现错误,请重新启动
Reboot if still got error
$ reboot
来自docker官方文档:
manage-docker-as-a-non-root-user
Taken from the docker official documentation: manage-docker-as-a-non-root-user
这篇关于如何修复Docker:获得权限被拒绝的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文