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:

  • How to wait for postgres startup in ENTRYPOINT?
  • AWS Configure Bash One Liner
  • How can I run bash in a new container of a docker image?
  • Bash in docker container has weird behaviour: “prompt jumps around”
  • Issue when I try to create a docker image [duplicate]
  • Properly automate a docker script in Python
  • [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.

  • Integrating Docker into the existing TFS-based infrastructure (not web-apps) [closed]
  • Why docker exec is killing nohup process on exit?
  • Docker run/star/exec?
  • How to speed up CI build times when using docker?
  • User-data script not executed when starting EC2 instance from AWS CLI
  • Writing data to file in Dockerfile
  • 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.