docker daemon须运行在root用户下,非root用户要使用sudo,原因在官方文档写到:
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 use sudo when you use the docker command, create a Unix group called docker and add users to it. When the docker daemon starts, it makes the ownership of the Unix socket read/writable by the docker group.
非root用户不使用sudo执行docker命令
$ sudo groupadd docker
创建docker用户组。$ sudo usermod -aG docker $USER
添加用户到docker用户组。$ sudo systemctl restart docker.service
重启docker daemon并重新登录$ docker run hello-world
测试下吧。