简体   繁体   English

如何在基于 dockerfile 的容器中运行 Jenkins 管道?

[英]How to run Jenkins pipeline in a container based on a dockerfile?

I'm trying to run a pipeline inside a container based on a dockerfile I've stored in my SCM.我正在尝试在基于存储在 SCM 中的 dockerfile 的容器内运行管道。

Here below the beginning of my pipeline:在我的管道开始的下面:

pipeline {
    agent { 
        dockerfile {
            dir '002_CICD'
        }

    }
....

When I try to run the pipeline I have the following error:当我尝试运行管道时,出现以下错误:

   + docker build -t 66dae53280bc29614c69b505e48424c25e689b91 -f 002_CICD/Dockerfile 002_CICD
/var/jenkins_home/workspace/AMP_app_docker_pipe@tmp/durable-cbf3977b/script.sh: 1:
 /var/jenkins_home/workspace/AMP_app_docker_pipe@tmp/durable-cbf3977b/script.sh: docker: not found

To run the docker container I've installed the following Jenkins plugins:为了运行 docker 容器,我安装了以下 Jenkins 插件:

  1. Docker plugin Docker插件
  2. docker-buil-step码头工人建造步骤
  3. Docker Pipeline Docker流水线
  4. Docker commons plugins Docker 公用插件
  5. Docker API plugin Docker API插件

I've also enabled the docker API on a remote server and the connections looks fine.我还在远程服务器上启用了 docker API 并且连接看起来很好。

What am I missing?我错过了什么? Many thanks非常感谢

What you are trying to implement is a docker in docker setup(quite used with regard to the CI process)您要实现的是 docker 设置中的 docker (在 CI 过程中非常常用)

As your jenkins is running inside a container you need to install a docker (cli/client) in your Dockerfile hence the error docker not found. As your jenkins is running inside a container you need to install a docker (cli/client) in your Dockerfile hence the error docker not found.

This docker client is will use the docker engine of the host for performing all the operations此 docker 客户端将使用主机的 docker 引擎来执行所有操作

With regards to the error关于错误

Cannot connect to the Docker daemon at unix:///var/run/docker.sock无法连接到 unix:///var/run/docker.sock 处的 Docker 守护程序

This can occur if the jenkins user doesn't have access to the host /var/run/docker.sock.如果 jenkins 用户无权访问主机 /var/run/docker.sock,则可能会发生这种情况。 Check the permissions of this file on host and the associated permissions of the user with which jenkins is running检查主机上此文件的权限以及运行 jenkins 的用户的相关权限

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM