【问题标题】:Jenkins pipeline can't build docker imageJenkins 管道无法构建 docker 镜像
【发布时间】:2018-06-15 17:18:19
【问题描述】:

我正在尝试使用 Jenkins 中的声明性管道从 Dockerfile 构建 docker 映像。我已成功将“jenkins”用户添加到 docker 组,并且可以手动以 jenkins 用户身份运行“docker run hello-world”。但是,当我尝试通过管道构建时,我什至无法运行 'docker run hello-world':

来自管道:

[workspace] Running shell script
+ whoami
jenkins
[workspace] Running shell script
+ groups jenkins
jenkins : jenkins docker
[workspace] Running shell script
+ docker run hello-world
docker: 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.30/containers/create: dial unix 
/var/run/docker.sock: connect: permission denied.

手动进入 Jenkins 并切换到“jenkins”用户:

*********@auto-jenkins-01:~$ sudo su - jenkins -s/bin/bash
jenkins@auto-jenkins-01:~$ docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
 3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

其他一些有用的信息:Jenkins 正在从 VM 运行。

【问题讨论】:

    标签: docker jenkins dockerfile jenkins-pipeline


    【解决方案1】:

    需要通过编辑 /etc/default/docker 并添加 jenkins 用户组权限给 docker unix socket:

    DOCKER_OPTS=' -G jenkins'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-16
      • 2017-09-15
      • 1970-01-01
      • 2022-12-11
      • 2018-06-19
      • 2018-05-14
      • 2019-11-15
      • 1970-01-01
      相关资源
      最近更新 更多