本地 Jenkins 安装没有 Docker 权限

Local Jenkins install has no Docker rights

我在 Ubuntu 19.04 机器上安装了 Docker (19.03.3) 和 Jenkins(来自 https://jenkins.io/download/ 的 2.190.2 LTS)。然后我创建了一个从我创建的示例 Git 存储库加载 Jenkinsfile 的管道。一切正常,直到 Jenkins 指示 Docker 拉取图像。响应是系统没有权限这样做。我已经将我的系统用户添加到 docker 组 (sudo usermod -aG docker $USER) 并在我的终端中成功测试了 docker pull node:6-alpine。但是詹金斯还是失败了。

有人知道问题出在哪里吗?我想这不是很复杂,而是典型的配置错误。

Jenkins 管道控制台输出:

Started by user John Doe
Obtained Jenkinsfile from git http://repo.myserver.com/john/example-app.git
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/workspace/example-app-builder
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
using credential jenkins
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url http://repo.myserver.com/john/example-app.git # timeout=10
Fetching upstream changes from http://repo.myserver.com/john/example-app.git
 > git --version # timeout=10
using GIT_ASKPASS to set credentials Credentials for repo.myserver.com.
 > git fetch --tags --force --progress -- http://repo.myserver.com/john/example-app.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision f578983d6e153b3063e184c8df194dcff6ee39ab (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f f578983d6e153b3063e184c8df194dcff6ee39ab # timeout=10
Commit message: "Add initial Jenkinsfile."
 > git rev-list --no-walk f578983d6e153b3063e184c8df194dcff6ee39ab # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] isUnix
[Pipeline] sh
+ docker inspect -f . node:6-alpine
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.40/containers/node:6-alpine/json: dial unix /var/run/docker.sock: connect: permission denied
[Pipeline] isUnix
[Pipeline] sh
+ docker pull node:6-alpine
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.40/images/create?fromImage=node&tag=6-alpine: dial unix /var/run/docker.sock: connect: permission denied
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE

您的 Jenkins 没有 运行 与 dockers 用户。它 运行 与用户 jenkins 相关。因此,为了允许用户 jenkins 创建 Docker 容器,命令应如下所示:

sudo usermod -aG docker jenkins