docker官网中有说明:
The Docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root and other users can only access it using sudo. The Docker daemon always runs as the root user.
If you don’t want to preface the docker command with sudo, create a Unix group called docker and add users to it. When the Docker daemon starts, it creates a Unix socket accessible by members of the docker group.
设置步骤:
1、创建docker用户组
$ sudo groupadd docker
2、添加当前用户至docker用户组
$ sudo usermod -aG docker $USER
3、更新用户组权限
$ newgrp docker
4、验证
$ docker run hello-world
需要执行第三步
否则会出现如下问题:
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.40/images/json: dial unix /var/run/docker.sock: connect: permission denied

本文详细介绍如何配置Docker以允许非root用户无需使用sudo即可运行Docker命令。通过创建docker用户组,将用户添加到该组,并更新用户组权限,使用户能够直接与Docker守护进程交互。
1825

被折叠的 条评论
为什么被折叠?



