gpt4 book ai didi

jenkins - 无法让 Jenkins Docker slave 构建 docker 镜像

转载 作者:行者123 更新时间:2023-12-02 17:56:39 24 4
gpt4 key购买 nike

我目前正在尝试将 Docker 与 Jenkins 结合使用,以简化新项目的 CI/CD 工作流程。我在安装了 Docker 1.12 的 Mac 上执行此操作。

这就是我所做的:

  • 使用 docker machine 创建新的 Docker 服务器
  • 使用官方 Jenkins Docker 镜像在该服务器上启动 Jenkins 实例
  • 安装“Yet Another Docker Plugin”和“CloudBees Docker Pipeline”插件。
  • 使用上面Docker服务器的IP和第三方Docker DinD镜像tehranian/dind-jenkins-slave添加一个“Docker Cloud”

  • 通过此设置,我运行了一个非常简单的管道作业,如下所示:
    node('docker') {
    docker.image('hseeberger/scala-sbt').inside {
    stage 'Checkout'
    echo 'We got here!'
    }
    }

    Jenkins 按预期启动 Docker 实例并执行作业。所以基本的 Docker 设置按预期工作。

    但是作业中的 Docker 命令失败。日志输出如下所示:
    [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 并使用 docker-machine env node 的内容在您正在运行的 shellscript 中。

    关于jenkins - 无法让 Jenkins Docker slave 构建 docker 镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38584307/

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