Linux 平台普通用户使用 docker 报错的解决方法:dial unix /var/run/docker.sock: connect: permission denied
推荐此种方法
进入该普通用户的终端,并执行
dockerd-rootless-setuptool.sh install
提示如下,执行下面的那段脚本,安装 uidmap
[ERROR] Missing system requirements. Run the following commands to
[ERROR] install the requirements and run this tool again.
########## BEGIN ##########
sudo sh -eux <<EOF
# Install newuidmap & newgidmap binaries
apt-get install -y uidmap
EOF
########## END ##########
再次执行
dockerd-rootless-setuptool.sh install
提示:
[INFO] Installed docker.service successfully.
[INFO] To control docker.service, run: `systemctl --user (start|stop|restart) docker.service`
[INFO] To run docker.service on system startup, run: `sudo loginctl enable-linger skiy`
[INFO] Creating CLI context "rootless"
Successfully created context "rootless"
[INFO] Make sure the following environment variables are set (or add them to ~/.bashrc):
export PATH=/usr/bin:$PATH
export DOCKER_HOST=unix:///run/user/1000/docker.sock
将上述两行环境变量添加到文件 ~/.bashrc
中,并应用(source ~/.bashrc
)。
按正常的 systemd 命令行使用即可(执行时需要添加参数 --user
)。
systemctl --user status docker
设置开机启动
sudo loginctl enable-linger ubuntu
不推荐此种方法
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.24/containers/git-alpine/json": dial unix /var/run/docker.sock: connect: permission denied
cd /var/run
sudo chmod 666 docker.sock