【Docker】dial unix /var/run/docker.sock: connect: permission denied.


这个错误的产生,主要是因为当前所用用户权限不足导致的。

可以使用如下命令,快速解决:

sudo setfacl --modify user:$USER:rw /var/run/docker.sock

此处对上述命令做一下解释 man setfacl

NAME
       setfacl - set file access control lists
SYNOPSIS
       setfacl [-bkndRLPvh] [{-m|-x} acl_spec] [{-M|-X} acl_file] file ...
       setfacl --restore=file
DESCRIPTION
...
       The -m (--modify) and -M (--modify-file) options modify the ACL of a file or directory.  ACL entries for this operation must include permissions.

可以理解,setfact 用于为用户($USER)对文件(/var/run/docker.sock)的访问设置权限。

参考文档

  1. How to fix "dial unix /var/run/docker.sock: connect: permission denied" when group permissions seem correct?
  2. setfacl命令的基本用法