Docker: not found in Jenkins pipeline

Hi there,

I spent 3 days searching and trying many possible ways to fix this issue and I couldn’t

What I’m trying to do is simply run docker commands in Jenkins pipeline like docker ps, but I’m getting this error

[app] Running shell script
+ docker ps
/var/jenkins_home/workspace/app@tmp/durable-e839f204/script.sh: 2: 
/var/jenkins_home/workspace/app@tmp/durable-e839f204/script.sh: docker: not found

I’m running Jenkins docker container using this command:

docker run -p 8080:8080 -p 50000:50000 -v /var/run/docker.sock:/var/run/docker.sock --name jenkins jenkins

I understood that now Jenkins container has access to the docker in the host machine, so what’s wrong here?

You need to run Jenkins in “Privileged mode”

Thanks for your help, but unfortunately I got the same error

docker run -ti -p 8080:8080 -p 50000:50000 -v /var/run/docker.sock:/var/run/docker.sock --privileged --name jenkins jenkins

This is how I’m running it now, do I need to install docker using Configure System Tools?

there is a direct jenkins pipeline integration.

https://go.cloudbees.com/docs/cloudbees-documentation/cje-user-guide/index.html#docker-workflow

when you do not use it, you need to make sure, that your build nodes have docker installed, which doesn’t seem to be given in your case.

Now I’m trying this way:

docker run -d -v /var/run/docker.sock:/var/run/docker.sock \
              -v $(which docker):/usr/bin/docker -p 8088:8088 jenkins-docker

But I’m getting this error:

docker: Error response from daemon: error while creating mount source path '/usr/local/bin/docker': chown /usr/local/bin/docker: no such file or directory.

I use Jenkins on a docker image, and I use it to build docker images, I have installed docker on the Jenkins image as well, I did it so I can control the docker version. I still need to run it in privileged mode though. I know there is a way to access the host Docker, but I haven’t tried too hard to get it to go.

1 Like

I wrote this a while ago, but it can still be useful and give some details (not specific to Jenkins) about the challenges of using Docker-in-Docker vs. binding the host Docker socket. I hope it helps!
http://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/

There is a confusion where the docker command can run.

It can run inside Jenkins host. Just check if docker is installed along with the Jenkins.
It can run inside container which is created by Jenkins. In this case an image should already contain a docker installation if you plan to use a docker inside of a container.

Run docker run -u command to pass the host’s docker group id at runtime, keeping the jenkins image portable.

grep docker /etc/group # GID
docker run  -p 8080:8080 -p 50000:50000 -d -u jenkins:GID  --name myjenkins jenkins:lst
2 Likes

Did you end up solving the issue? I did not fully understand the proposed solutions, but I’m having exactly the same issue.

Thank you,
João

I get this error message when running a custom image based on jenkins/jenkins in docker swarm mode: Ignoring unsupported options: privileged

My custom image has blue ocean plugin installed. Here is the compose file:

version: "3.5"

services:

    jenkins:
        image: quay.io/shazchaudhry/docker-jenkins
        user: root
        privileged: true
        environment:
            - JENKINS_OPTS='--prefix=/jenkins'
        volumes:
            - /var/run/docker.sock:/var/run/docker.sock
            - jenkins_home:/var/jenkins_home
        secrets:
            - jenkins-user
            - jenkins-pass

volumes:
    jenkins_home:

secrets:
    jenkins-pass:
        external: true
    jenkins-user:
        external: true

My Jenkinsfile / pipeline runs fine on Ubuntu but does not appear to work on RHEL 7.3 and complains docker: not found. My environment is:

  • RHEL Server release 7.3
  • Docker version 17.12.0-ce
  • Jenkins ver. 2.106

Has anyone got a jenkins pipeline working in docker swarm mode in RHEL 7.3?

@leoaref - I am stuck with the same problem that you reported back in Apr '17, docker: not found. Did you ever manage to resolve your issue?

I am able to run jenkins pipeline fine in ubuntu. but the same configuration and pipeline does not work in RHEL 7.3.

If you have found a resolution to you issue, I will be grateful if you could respond with the solution

Solution is to install docker in your jenkins container.

Anyone interested to find out more may want to take a look at https://github.com/shazChaudhry/docker-jenkins/blob/ee0f386fd1706829b956cb2e723c0f2935496933/Dockerfile

@jpetazzo is it possible to implement the side car pattern from a jenkins pipeline script where jenkins itself is installed on a container i.e. can the agent being instantiated from the pipeline script run from the host machine? Per your post, I would rather stay away from running docker inside a docker container.

Are there any example of installing the Docker CLI using your base image’s packaging system, or using the Docker API?

Edit: Never mind, that’s literally what you explain in the article thanks!

Yes, I found the solution. Following command is working fine for me.

docker run --rm -u root -p 8080:8080 -v jenkins-data:/var/jenkins_home -v $(which docker):/usr/bin/docker -v /var/run/docker.sock:/var/run/docker.sock -v "$HOME":/home jenkinsci/blueocean
5 Likes

it doesn’t work with me ,image . exec the command in docker container

You should not mount the binary as mentioned in the answer above but instead install the docker client in your container.
Reason is that the binary is linking against a shared library which you would need to mount as well into the container. But doing that would result in other issues (eg. wrong system dependencies).

Please have a look as well here: Using Docker-in-Docker for your CI or testing environment? Think twice.

Former versions of this post advised to bind-mount the docker binary from the host to the container. This is not reliable anymore, because the Docker Engine is no longer distributed as (almost) static libraries.

Thanks is worked for me i just added this

 -v $(which docker):/usr/bin/docker
1 Like

docker run --name jenkins -p 8080:8080 -p 50000:50000
-v /var/run/docker.sock:/var/run/docker.sock
-v $(which docker):/usr/bin/docker
-v /home/jenkins_home:/var/jenkins_home
jenkins/jenkins

1 Like

The following worked perfectly for me:

Basically the solution is to build a docker container which will build upon jenkins and install docker into it, at the end its basically jenkins with the docker client (not server) installed, and when running it you connect it to the host docker.sock as was mentioned above as well

1 Like