Jenkins – Cannot run program “docker”

Trying to use a docker agent with a declarative pipeline…

pipeline
{
    agent
    {
        docker
        {
            image 'rubygem/calabash-cucumber'
        }
    }
...

The build job finds the docker image but then skips all stages and quits with a Java exception:

  • automatic docker login within a bash script
  • How to pass host ip address to docker in mac OS?
  • Run shell script inside a container
  • prepend command with env variable - including sub command
  • docker ubuntu container: shell linked to bash still starts shell
  • Simple docker deployment tactics
  • [test_automation] Running shell script
    + docker pull rubygem/calabash-cucumber
    Using default tag: latest
    latest: Pulling from rubygem/calabash-cucumber
    Digest: sha256:cc6a06017009f0a68b93db33c2ced09a224ce2b8754efadaed16c18190e56ee4
    Status: Image is up to date for rubygem/calabash-cucumber:latest
    [Pipeline] }
    [Pipeline] // stage
    [Pipeline] sh
    [test_automation] Running shell script
    + docker inspect -f . rubygem/calabash-cucumber
    .
    [Pipeline] withDockerContainer
    [Pipeline] // withDockerContainer
    [Pipeline] }
    [Pipeline] // node
    [Pipeline] stage
    [Pipeline] { (Declarative: Post Actions)
    [Pipeline] echo
    All stages finished.
    [Pipeline] echo
    Cleaning up workspace ...
    [Pipeline] echo
    Build failed!
    [Pipeline] }
    [Pipeline] // stage
    [Pipeline] End of Pipeline
    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:245)
        at hudson.Proc$LocalProc.<init>(Proc.java:214)
        at hudson.Launcher$LocalLauncher.launch(Launcher.java:850)
        at hudson.Launcher$ProcStarter.start(Launcher.java:384)
    

    Anyone know why this happens? I’ve added all my bash PATH variables in Jenkins general settings, added jenkins User to staff group. None helped.

  • How to run an application inside docker safely
  • how to set supervisor to run a shell script
  • Accessing the number of arguments pass into a docker run command script
  • Shell script to cleanup specified docker containers using grep
  • Travis ci in docker failing
  • docker logs and buffered output
  • One Solution collect form web for “Jenkins – Cannot run program “docker””

    Adding ~/.zshenv for zshell (or other file) to put docker in the path. I did this and problem resolved:

    $ cat ~/.zshenv
    export PATH=/usr/local/bin:$PATH
    

    I answered at https://stackoverflow.com/a/44197275/2557645

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.