all*_*ije 8 permissions sudo docker groups
据答案约泊坞窗这个问题,运行它作为一个非root是那么容易,因为添加的非root用户名到docker组,注销并回。果然,当我用它作为sudo对hello-world图像进展顺利。但是对于另一个名为whalefortune我的测试图像,我仍然收到access denied错误——见下文。
通常不再可以以非 root 用户身份运行 docker 了吗?我使用的是 Ubuntu 19.04,它比示例版本更新,并且有人提到可能存在以非 root 身份运行 docker 的安全漏洞。
我的想法是以普通用户身份运行 nvidia-docker,这可能吗(甚至是个好主意)?
$ sudo docker run --rm hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:6540fc08ee6e6b7b63468dc3317e3303aae178cb8a45ed3123180328bcc1d20f
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://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
$ docker run --rm dbkdoc/whalefortune
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'.
Run Code Online (Sandbox Code Playgroud)
如果您不想在 docker 命令前使用 sudo,请创建一个名为 docker 的 Unix 组并向其中添加用户。当 Docker 守护进程启动时,它会创建一个可由 docker 组成员访问的 Unix 套接字。
警告:
docker 组授予与 root 用户等效的权限。有关这如何影响系统安全性的详细信息,请参阅Docker 守护进程攻击面。
如果您仍然想在没有 docker 的情况下运行sudo:
如果 docker 组不存在,请添加它:
sudo groupadd docker
Run Code Online (Sandbox Code Playgroud)将连接的用户 "$USER" 添加到 docker 组。如果您不想使用当前用户,请更改用户名以匹配您的首选用户:
sudo usermod -aG docker $USER
Run Code Online (Sandbox Code Playgroud)执行newgrp docker或注销/登录以激活对组的更改(如果在虚拟机上测试,可能需要重新启动虚拟机以使更改生效)。
您可以使用
docker run hello-world
Run Code Online (Sandbox Code Playgroud)
检查是否可以在没有 sudo 的情况下运行 docker。
PS:
如果您sudo在将用户添加到docker组之前最初使用 Docker CLI 命令运行,您可能会看到以下错误,这表明您的~/.docker/目录是由于sudo命令而以错误的权限创建的。
WARNING: Error loading config file: /home/user/.docker/config.json -
stat /home/user/.docker/config.json: permission denied
Run Code Online (Sandbox Code Playgroud)
要解决此问题,请删除~/.docker/目录(它会自动重新创建,但所有自定义设置都将丢失),或使用以下命令更改其所有权和权限:
sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
sudo chmod g+rwx "$HOME/.docker" -R
Run Code Online (Sandbox Code Playgroud)
来源: Docker 文档
| 归档时间: |
|
| 查看次数: |
13929 次 |
| 最近记录: |