Docker daemon socket权限不足

发布时间:2020-04-16 14:51:11编辑:admin阅读(2280)

    一、概述

    普通用户执行命令:docker ps报错,具体信息如下:

    docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.38/containers/create: dial unix /var/run/docker.sock: connect: permission denied.

    出现上面问题是因为:

    Manage Docker as a non-root user
    即:管理Docker的不是root用户

     

    原文表述:

    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.

     

    即:docker进程使用Unix Socket而不是TCP端口。而默认情况下,Unix socket属于root用户,需要root权限才能访问。

     

    二、解决方案

    方案一:使用sudo获取管理员权限,运行docker命令
    方案二:添加docker group组,将用户添加进去


    环境说明

    操作系统:centos 7.6

    docker版本:19.03.5

     

    由于采用的是jumpserver方式登录,开发人员使用的是develop账号。

    docker安装之后,默认会创建组docker,因此不需要再创建了。

     

    执行命令

    使用root账号登录目标服务器

    #将登陆用户develop加入到docker用户组中
    gpasswd -a develop docker
    #更新用户组
    newgrp docker

    切换到develop用户进行测试

    su develop
    docker ps


    输出正常,则表示成功了。

     

     

    本文参考链接:

    https://www.jianshu.com/p/a0cf03605c42


关键字