構建自動化,需要jenkins用戶構建docker,執行報錯,按照下圖操作,給jenkins添加多一個組docker即可。
普通用戶jenkins下執行docker命令報錯沒有權限,root用戶下可以。
jenkins@saas:~$ docker images
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.24/images/json: dial unix /var/run/docker.sock: connect: permission denied
jenkins@saas:~$ groups
jenkins
jenkins@saas:~$ exit
root@saas:# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
root@saas# groups
root
root@saas# usermod -a -G jenkins,docker jenkins ###添加jenkins多一個組,
root@saas# groups jenkins
jenkins : jenkins docker
root@saas# su jenkins
jenkins@saas:~$
jenkins@saas:~$
jenkins@saas:~$ docker images ###已經可以正常執行docker
REPOSITORY TAG IMAGE ID CREATED SIZE
jenkins@saas:~$
linux用戶添加到多個組
usermod -G groupname username (這種會把用戶從其他組中去掉,只屬於該組)
如:usermod -G git git (git只屬於git組)
usermod -a -G groupname username (把用戶添加到這個組,之前所屬組不影響)
如:usermod -a -G www git (git屬於之前git組,也屬於www組)
