简体   繁体   English

詹金斯:无法运行程序“docker”:错误=2,没有那个文件或目录

[英]Jenkins : Cannot run program “docker”: error=2, No such file or directory

I have installed Jenkins on my local machine which runs on MacOS High Sierra and have docker installed .我已经在我的本地机器上安装了 Jenkins,它在 MacOS High Sierra 上运行并安装了 docker。 I am trying to run a simple pipeline example which uses docker.我正在尝试运行一个使用 docker 的简单管道示例。 I have added the following lines to pipeline :我在管道中添加了以下几行:

pipeline {
    agent {
        docker { image 'node:7-alpine' }
    }
    stages {
        stage('Test') {
            steps {
                sh 'node --version'
            }
        }
    }
}

Then from the WebGUI, I click on build now and it is failing.然后从 WebGUI 中,我单击“立即构建”但它失败了。 Console output showing the error as follows :显示错误的控制台输出如下:

java.io.IOException: error=2, No such file or directory
 at java.lang.UNIXProcess.forkAndExec(Native Method)
 at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
 at java.lang.ProcessImpl.start(ProcessImpl.java:134)
 at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
 at hudson.Proc$LocalProc.<init>(Proc.java:249)
 at hudson.Proc$LocalProc.<init>(Proc.java:218)
 at hudson.Launcher$LocalLauncher.launch(Launcher.java:929)
 at hudson.Launcher$ProcStarter.start(Launcher.java:449)
 at org.jenkinsci.plugins.docker.workflow.client.DockerClient.launch(DockerClient.java:296)
 at org.jenkinsci.plugins.docker.workflow.client.DockerClient.launch(DockerClient.java:277)
 at org.jenkinsci.plugins.docker.workflow.client.DockerClient.launch(DockerClient.java:274)
 at org.jenkinsci.plugins.docker.workflow.client.DockerClient.version(DockerClient.java:246)
 at org.jenkinsci.plugins.docker.workflow.WithContainerStep$Execution.start(WithContainerStep.java:141)
 at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:229)
 at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:153)
 at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
 at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:48)
 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
 at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:20)
Caused: java.io.IOException: Cannot run program "docker": error=2, No such file or directory
 at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
 at hudson.Proc$LocalProc.<init>(Proc.java:249)
 at hudson.Proc$LocalProc.<init>(Proc.java:218)
 at hudson.Launcher$LocalLauncher.launch(Launcher.java:929)
 at hudson.Launcher$ProcStarter.start(Launcher.java:449)
 at org.jenkinsci.plugins.docker.workflow.client.DockerClient.launch(DockerClient.java:296)
 at org.jenkinsci.plugins.docker.workflow.client.DockerClient.launch(DockerClient.java:277)
 at org.jenkinsci.plugins.docker.workflow.client.DockerClient.launch(DockerClient.java:274)
 at org.jenkinsci.plugins.docker.workflow.client.DockerClient.version(DockerClient.java:246)
 at org.jenkinsci.plugins.docker.workflow.WithContainerStep$Execution.start(WithContainerStep.java:141)
 at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:229)
 at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:153)
 at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
 at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:48)
 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
 at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:20)
 at org.jenkinsci.plugins.docker.workflow.Docker$Image.inside(jar:file:/Users/coder/.jenkins/plugins/docker-workflow/WEB-INF/lib/docker-workflow.jar!/org/jenkinsci/plugins/docker/workflow/Docker.groovy:135)
 at org.jenkinsci.plugins.docker.workflow.Docker.node(jar:file:/Users/coder/.jenkins/plugins/docker-workflow/WEB-INF/lib/docker-workflow.jar!/org/jenkinsci/plugins/docker/workflow/Docker.groovy:66)
 at org.jenkinsci.plugins.docker.workflow.Docker$Image.inside(jar:file:/Users/coder/.jenkins/plugins/docker-workflow/WEB-INF/lib/docker-workflow.jar!/org/jenkinsci/plugins/docker/workflow/Docker.groovy:123)
 at org.jenkinsci.plugins.pipeline.modeldefinition.agent.impl.DockerPipelineScript.runImage(jar:file:/Users/coder/.jenkins/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/agent/impl/DockerPipelineScript.groovy:57)
 at org.jenkinsci.plugins.pipeline.modeldefinition.agent.impl.AbstractDockerPipelineScript.configureRegistry(jar:file:/Users/coder/.jenkins/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/agent/impl/AbstractDockerPipelineScript.groovy:74)
 at org.jenkinsci.plugins.pipeline.modeldefinition.agent.impl.AbstractDockerPipelineScript.run(jar:file:/Users/coder/.jenkins/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/agent/impl/AbstractDockerPipelineScript.groovy:52)
 at org.jenkinsci.plugins.pipeline.modeldefinition.agent.CheckoutScript.checkoutAndRun(jar:file:/Users/coder/.jenkins/plugins/pipeline-model-extensions/WEB-INF/lib/pipeline-model-extensions.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/agent/CheckoutScript.groovy:66)
 at org.jenkinsci.plugins.pipeline.modeldefinition.agent.CheckoutScript.doCheckout(jar:file:/Users/coder/.jenkins/plugins/pipeline-model-extensions/WEB-INF/lib/pipeline-model-extensions.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/agent/CheckoutScript.groovy:42)
 at org.jenkinsci.plugins.pipeline.modeldefinition.agent.impl.LabelScript.run(jar:file:/Users/coder/.jenkins/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/agent/impl/LabelScript.groovy:44)
 at ___cps.transform___(Native Method)
 at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:57)
 at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109)
 at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:82)
 at sun.reflect.GeneratedMethodAccessor192.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
 at com.cloudbees.groovy.cps.impl.ClosureBlock.eval(ClosureBlock.java:46)
 at com.cloudbees.groovy.cps.Next.step(Next.java:83)
 at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
 at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
 at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:122)
 at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:261)
 at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
 at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$101(SandboxContinuable.java:34)
 at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.lambda$run0$0(SandboxContinuable.java:59)
 at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
 at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:58)
 at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:174)
 at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:332)
 at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:83)
 at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:244)
 at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:232)
 at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
 at java.util.concurrent.FutureTask.run(FutureTask.java:266)
 at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)
 at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
 at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
 at java.util.concurrent.FutureTask.run(FutureTask.java:266)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
 at java.lang.Thread.run(Thread.java:745)
Finished: FAILURE

Why this is happening ?为什么会这样? In the Jenkins documentation, they are only given this syntax and doesn't mentioned about anything else.在 Jenkins 文档中,他们只给出了这种语法,没有提到其他任何东西。

I hit the same problem as above.我遇到了与上面相同的问题。 I am not sure that my case is exactly the same as your but the TL;DR is that you need make sure that Docker is available to the PATH variable Jenkins is using.我不确定我的情况与您的情况完全相同,但 TL;DR 是您需要确保 Docker 可用于 Jenkins 正在使用的 PATH 变量。 Specifically the one it starts up with, which can be seen under Jenkins Home -> Manage Jenkins -> System Information .特别是它启动的那个,可以在Jenkins Home -> Manage Jenkins -> System Information下看到。

In my case, I am on a Mac and installed Jenkins through Homebrew.就我而言,我在 Mac 上并通过 Homebrew 安装了 Jenkins。 To fix the issue I edited the /usr/local/opt/jenkins-lts/homebrew.mxcl.jenkins-lts.plist file and changed it to the following:为了解决这个问题,我编辑了/usr/local/opt/jenkins-lts/homebrew.mxcl.jenkins-lts.plist文件并将其更改为以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>homebrew.mxcl.jenkins-lts</string>
    <key>ProgramArguments</key>
    <array>
      <string>/usr/libexec/java_home</string>
      <string>-v</string>
      <string>1.8</string>
      <string>--exec</string>
      <string>java</string>
      <string>-Dmail.smtp.starttls.enable=true</string>
      <string>-jar</string>
      <string>/usr/local/opt/jenkins-lts/libexec/jenkins.war</string>
      <string>--httpListenAddress=127.0.0.1</string>
      <string>--httpPort=8080</string>
    </array>
    <key>EnvironmentVariables</key>
    <dict>
      <key>PATH</key>
      <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
    </dict>
    <key>RunAtLoad</key>
    <true/>
  </dict>
</plist>

The important part here is:这里的重要部分是:

    <key>EnvironmentVariables</key>
    <dict>
      <key>PATH</key>
      <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
    </dict>

in my case, docker is available at /usr/local/bin .就我而言, docker/usr/local/bin可用。

I ran into some serious trouble with this too so I wanted to post my solution since I have not seen it around anywhere.我也遇到了一些严重的问题,所以我想发布我的解决方案,因为我没有在任何地方看到它。

My setup was: A Mac Mini running Mac OS Sierra with jenkins and docker both installed locally.我的设置是:运行 Mac OS Sierra 的 Mac Mini,jenkins 和 docker 都安装在本地。 Jenkins could not call docker in groovy scripts, but the shell had access to docker commands. Jenkins 无法在 groovy 脚本中调用 docker,但 shell 可以访问 docker 命令。

Solution:解决方案:

  1. Manage Jenkins > Global Tool Configuration管理 Jenkins > 全局工具配置
  2. Click to add a docker installation点击添加docker安装
  3. Name it whatever you wish, you will be using this name to identify the installation in the Groovy scripts随意命名,您将使用此名称来标识 Groovy 脚本中的安装
  4. Set the installation root to the installation location of your Docker (mine was in /usr/local by default).将安装根目录设置为 Docker 的安装位置(我的默认在 /usr/local 中)。 This did not work for me if I appended /bin this path as the docker plugin I was using in Jenkins does this automatically.如果我附加 /bin 这条路径,这对我不起作用,因为我在 Jenkins 中使用的 docker 插件会自动执行此操作。 We snooped around the source for docker-workflow-plugin to verify this ourselves.我们窥探了 docker-workflow-plugin 的源代码以自己验证这一点。
  5. Save these changes保存这些更改
  6. Open your Groovy script where you want to call your docker installation and surround your docker calls in a block statement like this:打开您要调用 docker 安装的 Groovy 脚本,并将您的 docker 调用包含在如下块语句中:

    docker.withTool('') { //whatever docker commands you wish to run here } docker.withTool('') { //任何你想在这里运行的 docker 命令 }

I enncounter the same problem on macOS recently.我最近在 macOS 上遇到了同样的问题。 It is solved by adding following lines to /usr/local/opt/jenkins-lts/homebrew.mxcl.jenkins-lts.plist通过/usr/local/opt/jenkins-lts/homebrew.mxcl.jenkins-lts.plist添加到/usr/local/opt/jenkins-lts/homebrew.mxcl.jenkins-lts.plist来解决

    <key>EnvironmentVariables</key>
    <dict>
      <key>PATH</key>
      <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
    </dict>

It also need restart jenkins brew services restart jenkins-lts .它还需要重启 jenkins brew services restart jenkins-lts

By the way, add PATH environment in jenkins web GUI don't fix the problem.顺便说一句,在 jenkins web GUI 中添加 PATH 环境并不能解决问题。 It work in some part and failed the whole process which make it more confused and mislead me too much.它在某些部分起作用并且整个过程都失败了,这使它更加困惑并误导了我太多。

暂无
暂无

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

相关问题 无法运行程序“ docker”,错误= 2,无此文件或目录 - Cannot run program “docker” error=2, No such file or directory 无法运行程序“...”错误= 2,没有这样的文件或目录(java) - Cannot run program “…” error=2, No such file or directory (java) 无法运行程序“mvn”错误=2,没有这样的文件或目录 - Cannot run program "mvn" error=2, No such file or directory 无法运行程序“ osascript”:error = 2,没有这样的文件或目录 - Cannot run program “osascript”: error=2, No such file or directory Docker ENV LD_PRELOAD 防止容器崩溃但抛出 java.io.IOException: Cannot run program &quot;ls&quot;: error=2, No such file or directory - Docker ENV LD_PRELOAD prevent container crash but throw java.io.IOException: Cannot run program "ls": error=2, No such file or directory ant jar错误:执行失败:java.io.IOException:无法运行程序... $ {aapt}“:error = 2,没有这样的文件或目录 - ant jar error: Execute failed: java.io.IOException: Cannot run program…${aapt}": error=2, No such file or directory 无法运行程序“wkhtmltopdf”:错误=2,没有这样的文件或目录 - 从 Java 获取此错误 - Cannot run program "wkhtmltopdf": error=2, No such file or directory - Getting this error from Java im4java中出现错误,无法运行程序“转换”:错误= 2,没有此类文件或目录 - Error in im4java, Cannot run program “convert”: error=2, No such file or directory 詹金斯:无法运行程序“hg” - Jenkins : Cannot run program “hg” JVM无法启动:java.io.IOException:无法运行程序“/ usr / libexec / StartupItemContext; error = 2,没有这样的文件或目录 - JVM failed to start: java.io.IOException: Cannot run program "/usr/libexec/StartupItemContext; error=2, No such file or directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM