1. 程式人生 > >非root用戶訪問Docker命令

非root用戶訪問Docker命令

str The upa 使用 contain path create 登陸 eas

#visudo k8s ? ? ALL=(ALL) ? ? ? ALL k8s ALL=(ALL) NOPASSWD: ALL
# cp ~/.kube/config ./kube/
# chown -R k8s.k8s config 

#su - k8s
$ vim ~/.bashrc 
export PATH=/opt/kube/bin:$PATH # generated by kubeasz
source <(kubectl completion bash)
$ source ~/.bashrc 
$ docker info
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.27/info: dial unix /var/run/docker.sock: connect: permission denied
``
解決方法:
sudo groupadd docker             #添加docker用戶組
sudo gpasswd -a k8s docker     #將登陸用戶加入到docker用戶組中
newgrp docker                    #更新用戶組
docker info                      #測試docker命令是否可以使用sudo正常使用

$ docker ps 
CONTAINER ID        IMAGE                                    COMMAND                  CREATED             STATUS                 PORTS                                                              NAMES
65bbf2cf8383        goharbor/nginx-photon:v1.6.0             "nginx -g ‘daemon ..."   2 hours ago         Up 2 hours (healthy)   0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:4443->4443/tcp   nginx
5fa9844dd451        goharbor/harbor-jobservice:v1.6.0        "/harbor/start.sh"       2 hours ago         Up 2 hours                                                                                harbor-jobservice
08578c554fd9        goharbor/harbor-ui:v1.6.0                "/harbor/start.sh"       2 hours ago         Up 2 hours (healthy)                                                                      harbor-ui
1b235b6ae0ab        goharbor/harbor-db:v1.6.0                "/entrypoint.sh po..."   2 hours ago         Up 2 hours (healthy)   5432/tcp                                                           harbor-db
fea430994084        goharbor/redis-photon:v1.6.0             "docker-entrypoint..."   2 hours ago         Up 2 hours             6379/tcp                                                           redis
4b1b64b5c18b        goharbor/harbor-adminserver:v1.6.0       "/harbor/start.sh"       2 hours ago         Up 2 hours (healthy)                                                                      harbor-adminserver
9e9478594905        goharbor/registry-photon:v2.6.2-v1.6.0   "/entrypoint.sh /e..."   2 hours ago         Up 2 hours (healthy)   5000/tcp                                                           registry
1da970f14a9a        goharbor/harbor-log:v1.6.0               "/bin/sh -c /usr/l..."   2 hours ago         Up 2 hours (healthy)   127.0.0.1:1514->10514/tcp                                          harbor-log

非root用戶訪問Docker命令