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

相關文章
相關標籤/搜索