gpt4 book ai didi

docker - Jenkins触发时如何解决Docker权限错误

转载 作者:IT老高 更新时间:2023-10-28 12:43:01 26 4
gpt4 key购买 nike

我的 Jenkins 不在 Docker 容器中运行,只是传统安装到 VPS。执行简单 test project 时出现以下错误.我正在使用 Ubuntu 14、java 7 和稳定的 Jenkins。我尝试了所有可以在谷歌上找到的方法,但无法正常工作。

我正在尝试执行这个 shell

docker build --pull=true -t nick/hello-jenkins:$GIT_COMMIT .

代码更改后。

这里是错误:

Got permission denied while trying to connect to the Docker daemon socket at unix: ....

Started by user nicolas xu
Building in workspace /var/lib/jenkins/workspace/hello-Jenkins
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url https://github.com/nicolasxu/hello-nick-jenkins.git # timeout=10
Fetching upstream changes from https://github.com/nicolasxu/hello-nick-jenkins.git
> git --version # timeout=10
> git fetch --tags --progress https://github.com/nicolasxu/hello-nick-jenkins.git +refs/heads/*:refs/remotes/origin/*
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10
> git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision d94ae21a8a2cf58ffc790dcad15bd851fb17df5a (refs/remotes/origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f d94ae21a8a2cf58ffc790dcad15bd851fb17df5a
> git rev-list d94ae21a8a2cf58ffc790dcad15bd851fb17df5a # timeout=10
[hello-Jenkins] $ /bin/sh -xe /tmp/hudson5076309502904684976.sh
+ docker build --pull=true -t nick/hello-jenkins:d94ae21a8a2cf58ffc790dcad15bd851fb17df5a .
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.27/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&pull=1&rm=1&shmsize=0&t=nick%2Fhello-jenkins%3Ad94ae21a8a2cf58ffc790dcad15bd851fb17df5a&ulimits=null: dial unix /var/run/docker.sock: connect: permission denied
Build step 'Execute shell' marked build as failure
Finished: FAILURE

我可以在控制台中以 root 身份运行 'docker' 没问题,为什么 jenkins 不能尝试运行 'docker' 的 shell 命令?到底是怎么回事?完全糊涂了.......

最佳答案

在您的 VPS 服务器终端中,执行此操作以将您的 jenkins 用户添加到 docker 组:

sudo usermod -aG docker jenkins

然后重新启动您的 jenkins 服务器以刷新组。

考虑到这可能产生的任何安全问题:

Warning: The docker group grants privileges equivalent to the root user. For details on how this impacts security in your system, see Docker Daemon Attack Surface.

请参阅 docs


编辑(@iger 提到):只需确保从命令行重新启动 Jenkins(即 sudo service jenkins restart),而不是通过其余端点(http:///restart)

关于docker - Jenkins触发时如何解决Docker权限错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44444099/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com