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:

  • Bash parse docker status to check if local image is up to date
  • DockerFile : how to get bash command line after start?
  • Why does echo $VARIABLE, within a /bin/bash -c “…” section of a dockerfile run instruction, return empty on docker build?
  • How to transfer a environment variable into a dockerfile
  • Script fails at build but works from Docker container
  • nginx not starting inside Docker [duplicate]
  • [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.

  • Writing data to file in Dockerfile
  • How would I pass environment into docker using bash?
  • Ensure docker daemon is running on the host in script file
  • Why does my automated build run so slowly inside a Docker container?
  • “Failed to resolve IP”; “Lookup error” in bash script when joining dockerized serf agents
  • Running tests with Docker and Jenkins - Test Result
  • 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.