之前遇到的一个问题,使用非root用户时操作docker提示无权限,在查阅了一些文章之后自己又摸索出了一些更方便的方法,顺手记录下来。

一、问题发现

根据报错信息dial unix /var/run/docker.sock: connect: permission denied,可以看出,是因为当前用户对docker使用的unix domain socket文件/var/run/docker.sock无权限。

于是查看docker.sock相关信息:

ls -l /var/run/docker.sock
# srw-rw---- 1 root docker 0 /var/run/docker.sock

可以看到,权限模式为srw-rw----,所属用户为root,所属组为docker。因此有权限的用户包括root用户和docker组内的用户。

二、使用root用户进行操作

1. 使用sudo操作

sudo docker <args>

2. 切换root用户操作

sudo -i
docker <args>
exit

三、授予docker.sock操作权限

1. 单次授予,重启后失效

sudo chmod 666 /var/run/docker.sock

2. 永久授予

2.1. 将当前用户加入docker组(推荐)

sudo gpasswd -a $USER docker
# 或
sudo usermod -a -G docker $USER

2.2. 向所有用户授予权限

# 查看docker.socket配置
cat /usr/lib/systemd/system/docker.socket

可以看到以下内容

[Unit]
Description=Docker Socket for the API [Socket]
ListenStream=/var/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker [Install]
WantedBy=sockets.target

其中ListenStreamunix domain socket文件路径,SocketMode为权限模式,SocketUser为所属用户,SocketGroup为所属组。

我们只需修改SocketMode0666即可。

修改并保存完成后,重新加载守护并重启socket即可:

sudo systemctl daemon-reload
sudo systemctl restart docker.socket

再次使用docker发现不再报错,重启机器后仍然可用。

关于`dial unix /var/run/docker.sock: connect: permission denied`的处理方法笔记的更多相关文章

  1. docker dial unix /var/run/docker.sock: connect: permission denied

    Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker. ...

  2. 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.38/images/json: dial unix /var/run/docker.sock: conne

    使用docker报如下错误信息: Got permission denied while trying to connect to the Docker daemon socket at unix:/ ...

  3. docker 解决:Get http:///var/run/docker.sock/v1.19/version: dial unix /var/run/docker.sock: no such file or directory. Are you trying to connect to a TLS-enabled daemon without TLS?

    docker 安装之后,通过命令查看docker相关信息时,可能会出现错误:Get http:///var/run/docker.sock/v1.19/version: dial unix /var/ ...

  4. 输入docker ps 报错信息处理Get http:///var/run/docker.sock/v1.19/containers/json: dial unix /var/run/docker.sock: permission denied.

    完整错误信息 Get http:///var/run/docker.sock/v1.19/containers/json: dial unix /var/run/docker.sock: permis ...

  5. 【解决】Got permission denied while trying to connect to the Docker daemon socket at......dial unix /var/run/docker.sock: permission denied

    >>> 问题:搭建Portainer时,选择本地连接报错? >>>分析: 根据报错信息可知是权限问题. 可能原因一:使用了非root用户启用或连接docker &g ...

  6. docker Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post

    利用docker构建时,报错 + docker pull maven:3-alpine Got permission denied while trying to connect to the Doc ...

  7. 启动docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock

    启动docker提示: docker: Got permission denied while trying to connect to the Docker daemon socket at uni ...

  8. 【转载】Docker 安装后 报 Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? 解决办法

    Docker Docker 安装后 报 Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docke ...

  9. Cannot connect to the Docker daemon at unix:///var/run/docker.sock.问题解决

    出现Cannot connect to the Docker daemon at unix:///var/run/docker.sock时,先用tail -5f /var/log/upstart/do ...

  10. Docker未启动错误:Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

    此问题是因为Docker安装后未启动所致,执行以下命令启动docker: systemctl start docker.service 具体日志如下: Connecting to ... Connec ...

随机推荐

  1. MongoDB 中使用 explain 分析创建的索引是否合理

    MongoDB 中如何使用 explain 分析查询计划 前言 查询计划 explain explain 1.queryPlanner 2.executionStats 3.allPlansExecu ...

  2. 两个例子带你入门 Disruptor

    Disruptor 是英国外汇交易公司 LMAX 开发的一个高性能队列.很多知名开源项目里,比如 canal .log4j2. storm 都是用了 Disruptor 以提升系统性能 . 这篇文章, ...

  3. dedebiz实时时间调用

    {dede:tagname runphp='yes'}@me = date("Y-m-d H:i:s", time());{/dede:tagname}

  4. Solution Set -「ABC 197」

    「ABC 197A」Rotate Link. 略. #include<bits/stdc++.h> using namespace std; int main(){ char a,b,c; ...

  5. Vue2系列(lqz)——6-Vue-cli、7-Vue插件、8-Vue第三方框架之ElementUi

    文章目录 6 Vue-CLI 项目搭建 1 单文件组件 2 Vue-CLI 项目搭建 2.1 环境搭建 2.2 项目的创建 创建项目 启动/停止项目 打包项目 package.json中 2.3 认识 ...

  6. Arduino 麦克风声音传感器指南

    麦克风声音传感器 麦克风声音传感器,顾名思义,检测声音.它可以测量声音的响度. 这些传感器的种类繁多.  在下图中,您可以看到 Arduino 最常用的. 最左边是KY-038,右边是LM393麦克风 ...

  7. jmeter生成随机英文的几种方法

    第一种:用BeanShell后置处理程序 1.写脚本 import java.util.Random; String random(int s_length) {       strings= &qu ...

  8. Util应用框架 7.x 来了

    什么是Util应用框架? Util是一个.Net平台下的应用框架,旨在提升中小团队的开发能力,由工具类.分层架构基类.Ui组件,配套代码生成模板,权限等组成. Util应用框架 7.x介绍 Util应 ...

  9. CF1338A

    题目简化和分析: \(a_{i}\ge a_{i-1}\) 已经满足直接跳过 \(a_{i}<a_{i-1}\) 我们就要将其的差进行二进制的分解,使得 \(a_{i-1}=a_i\) 我也不知 ...

  10. VLAN虚拟网络

    VLAN 名称:vlan 虚拟局域网(virtual LAN) 用途 由于交换机所有的端口都在同一广播域,只要发送广播会产生大量的垃圾信息,同时会有病毒的安全隐患(病毒). 为了解决上述问题 1.物理 ...