Docker如何非root用户操做

 

1、为何 Docker 须要 root 权限

    如下下 Docker 官方文档的说明:  html

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 access it with sudo. For this reason, 
docker daemon always runs as the root user. 

  To avoid having 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.

2、Docker 使用非root用户操做的解决方案

    一、建立docker组

sudo groupadd docker

   

    二、将当前用户加入docker组

sudo gpasswd -a ${USER} docker

    
    三、从新启动docker服务 

    下面是 CentOS7 的命令,其余系统详见 Docker 官方文档:linux

# 下面是CentOS7的命令,其余系统详见 Docker 官方文档
sudo systemctl restart docker

     

    四、当前用户退出系统从新登录

# 运行docker命令 docker ps 查看已运行的容器

docker ps

# 运行docker命令 docker images 查看已下载的镜像

docker images

     

 

    参考文档:docker

    · Docker 官方文档:https://docs.docker.com/engine/installation/bash

    · Linux 命令大全:http://man.linuxde.net/socket

 

本文为博主原创文章,转载请注明出处!this

https://my.oschina.net/u/3375733/blog/spa

相关文章
相关标签/搜索