• 企业400电话
  • 微网小程序
  • AI电话机器人
  • 电商代运营
  • 全 部 栏 目

    企业400电话 网络优化推广 AI电话机器人 呼叫中心 网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    docker容器里面的root权限获取方法

    首先你的container得正在运行

    可通过sudo docker container ls或者sudo docker ps查看容器的CONTAINER ID

    最后执行命令(其中7509371edd48 为上面查到的CONTAINER ID)

    sudo docker exec -ti -u root 7509371edd48 bash

    补充:解决非root用户没有权限运行docker命令的问题

    问题描述:

    ”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.26/images/json: dial unix
    /var/run/docker.sock: connect: permission denied“

    原因(摘自docker手册):

    Manage Docker as a non-root user

    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.

    答案显而易见,要不用root用户,要不创建一个名为docker的用户组,并把你需要使用docker的非root用户添加到该组中,如果还不会搞,继续往下看。

    方法1:

    使用sudo获取管理员权限,运行docker命令,这个方法在通过脚本执行docker命令的时候会有很多局限性

    方法2:

    docker守护进程启动的时候,会默认赋予名为docker的用户组读写Unix socket的权限,因此只要创建docker用户组,并将当前用户加入到docker用户组中,那么当前用户就有权限访问Unix socket了,进而也就可以执行docker相关命令

    sudo groupadd docker   #添加docker用户组
    sudo gpasswd -a $USER docker   #将登陆用户加入到docker用户组中
    newgrp docker   #更新用户组

    以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。如有错误或未考虑完全的地方,望不吝赐教。

    上一篇:Apache压力测试工具的安装使用
    下一篇:使用docker更改容器内root密码的操作
  • 相关文章
  • 

    © 2016-2020 巨人网络通讯

    时间:9:00-21:00 (节假日不休)

    地址:江苏信息产业基地11号楼四层

    《增值电信业务经营许可证》 苏B2-20120278

    docker容器里面的root权限获取方法 docker,容器,里,面的,root,