非root用户访问Docker命令
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了非root用户访问Docker命令相关的知识,希望对你有一定的参考价值。
#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命令的主要内容,如果未能解决你的问题,请参考以下文章