一、在一臺運行了docker的服務器上,啓動374c3bec1f4b 鏡像的容器,這個鏡像中安裝docker(yum install docker -y)。
$ docker run -itd -v /var/run/docker.sock:/var/run/docker.sock --name docker_test 374c3bec1f4b
$ docker exec -it docker_test bash
二、進入docker_test容器後,非root用戶需要sudo才能執行docker命令:
$ docker ps
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES docker_test_p
a133a95841ef 374c3bec1f4b "/usr/bin/supervisord" 2 hours ago Up 3 hours docker_test
三、修改服務器上/var/run/docker/sock文件的權限後,其他用戶纔可以正常執行docker ps:
[root@test2 ~]# ll /var/run/docker.sock
srw-rw---- 1 root docker 0 Sep 4 08:30 /var/run/docker.sock