无法让Jenkins Docker slave生成Docker映像

无法让Jenkins Docker slave生成Docker映像,jenkins,docker,Jenkins,Docker,我目前正在与Docker和Jenkins一起进行试验,以简化新项目的CI/CD工作流程。我在安装了Docker 1.12的Mac上这样做 我就是这么做的: 使用docker machine创建新的docker服务器 使用正式的Jenkins Docker映像在该服务器上启动Jenkins实例 安装“另一个Docker插件”和“CloudBees Docker管道”插件 使用上面Docker服务器的IP和第三方Docker DinD映像tehranian/DinD jenkins slave添加“

我目前正在与Docker和Jenkins一起进行试验,以简化新项目的CI/CD工作流程。我在安装了Docker 1.12的Mac上这样做

我就是这么做的:

  • 使用docker machine创建新的docker服务器
  • 使用正式的Jenkins Docker映像在该服务器上启动Jenkins实例
  • 安装“另一个Docker插件”和“CloudBees Docker管道”插件
  • 使用上面Docker服务器的IP和第三方Docker DinD映像tehranian/DinD jenkins slave添加“Docker云”
  • 通过此设置,我运行了一个非常简单的管道作业,如下所示:

    node('docker') {
        docker.image('hseeberger/scala-sbt').inside {
            stage 'Checkout'
            echo 'We got here!'
        }
    }
    
    [Pipeline] node
    Still waiting to schedule task
    Docker-23ebf3d8dd4f is offline
    Running on Docker-23ebf3d8dd4f in /home/jenkins/workspace/docker-test
    [Pipeline] {
    [Pipeline] sh
    [docker-test] Running shell script
    + docker inspect -f . hseeberger/scala-sbt
    
    Cannot connect to the Docker daemon. Is the docker daemon running on this host?
    [Pipeline] sh
    [docker-test] Running shell script
    + docker pull hseeberger/scala-sbt
    Using default tag: latest
    Warning: failed to get default registry endpoint from daemon (Cannot connect to the Docker daemon. Is the docker daemon running on this host?). Using system default: https://index.docker.io/v1/
    Cannot connect to the Docker daemon. Is the docker daemon running on this host?
    [Pipeline] }
    [Pipeline] // node
    [Pipeline] End of Pipeline
    
    Jenkins按预期启动Docker实例并执行作业。因此,基本的Docker设置工作正常

    但是作业中的Docker命令失败。日志输出如下所示:

    node('docker') {
        docker.image('hseeberger/scala-sbt').inside {
            stage 'Checkout'
            echo 'We got here!'
        }
    }
    
    [Pipeline] node
    Still waiting to schedule task
    Docker-23ebf3d8dd4f is offline
    Running on Docker-23ebf3d8dd4f in /home/jenkins/workspace/docker-test
    [Pipeline] {
    [Pipeline] sh
    [docker-test] Running shell script
    + docker inspect -f . hseeberger/scala-sbt
    
    Cannot connect to the Docker daemon. Is the docker daemon running on this host?
    [Pipeline] sh
    [docker-test] Running shell script
    + docker pull hseeberger/scala-sbt
    Using default tag: latest
    Warning: failed to get default registry endpoint from daemon (Cannot connect to the Docker daemon. Is the docker daemon running on this host?). Using system default: https://index.docker.io/v1/
    Cannot connect to the Docker daemon. Is the docker daemon running on this host?
    [Pipeline] }
    [Pipeline] // node
    [Pipeline] End of Pipeline
    
    现在,当我浏览解决方案时,通常会提到Docker套接字需要作为卷提供给容器,但这似乎也不起作用


    既然一般的设置似乎正在运行,那么从站难道不需要像Jenkins插件一样首先启动Docker从站吗?也就是说,使用Docker服务器的URL来控制它?因为我假设这是一个非常常见的用例,所以Jenkins Docker slaves必须有一个Docker映像,可以开箱即用,对吗?我缺少什么?

    您可能需要设置docker env,并在运行的shellscript中使用
    docker machine env node的内容。

    由于鸡和蛋的情况,这将不起作用:如果没有运行的docker安装,该命令将无法运行。假设您按照建议的方式安装docker套接字,因此Jenkins编写的Docker容器位于/var/run/Docker.sock。Jenkins创建的Docker容器中的步骤由某个用户运行-该用户可以访问安装的Docker套接字吗?例如,用户是否在
    docker
    组中?我认为您不需要
    节点(“docker”)
    部分,根据:但是这不会解决您的问题。。我也有同样的问题。你修好了吗?