根据docker的官方文档的描述
https://docs.docker.com/install/linux/linux-postinstall/
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.
所以,只要把当前用户添加到docker用户组里面就可以了。
具体的操作步骤如下:
-
如果没有,则创建
docker
用户组。$ sudo groupadd docker
-
把当前用户加入docker用户组。
$ sudo usermod -aG docker $USER
-
退出当前会话然后重新登录,使用户加组操作生效
-
验证是否可以在免sudo的情况下执行docker命令。
$ docker run hello-world