Jenkins docker not found

28 views
Skip to first unread message

adrian lee

unread,
Feb 5, 2020, 10:44:57 AM2/5/20
to Jenkins Users
Hi all, 

I am trying to use docker with Jenkins. 

I installed it as a global toolconfiguration call myDocker. 

I then tried to write a pipeline script as below

```
pipeline {
   agent any
    
   // set path
   stages {
      stage ('set docker path'){
          steps{
              script{
                  def dockerHome = tool 'myDocker'
                  env.PATH = "${dockerHome}/bin:${env.PATH}"
              }
            sh 'docker ps'
          }
      }

      //delete
      stage('node') {
        agent {
            docker { image 'node:7-alpine' }
        }
        steps {
            sh 'node --version'
        }
      }


   }
}
```

however, it keeps throwing me an error

```
+ docker ps
/var/lib/jenkins/workspace/openFaaS_getdata@tmp/durable-270f2b11/script.sh: line 1: docker: command not found

```

I tried referencing other posts on stack overflow but could not find what is wrong. 

Any help?

Simon Richter

unread,
Feb 5, 2020, 12:19:38 PM2/5/20
to jenkins...@googlegroups.com
Hi,

On Wed, Feb 05, 2020 at 07:44:57AM -0800, adrian lee wrote:

> however, it keeps throwing me an error
>
> ```
> + docker ps
> /var/lib/jenkins/workspace/openFaaS_getdata@tmp/durable-270f2b11/script.sh:
> line 1: docker: command not found
>
> ```

> I tried referencing other posts on stack overflow but could not find what
> is wrong.

That is the same problem I'm having: the plugin responsible for handling
"agent { docker ... }" and "agent { dockerfile ... }" uses the Docker CLI
instead of the Docker API, so the "docker" program must be in the search
path.

There was a proposed fix[1] for that, but it seems that is dead.

What I'm doing now, until someone makes a better suggestion, is to build a
derived Jenkins container that adds the "docker" CLI tool to the image
using wget, and limit all builds to run on master so the tool is available.

Since the actual build happens inside a fresh container anyway, the only
annoying thing about this is that the build counts against master's
executors.

Simon

[1] https://github.com/jenkinsci/docker-workflow-plugin/pull/195
Reply all
Reply to author
Forward
0 new messages