Docker Community Forums

Share and learn in the Docker community.

Docker: not found in Jenkins pipeline

docker
ci

(Leoaref) #1

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?


(Andrew) #2

You need to run Jenkins in “Privileged mode”


(Leoaref) #3

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?


(Think) #4

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.


(Leoaref) #5

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.

(Andrew) #6

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.


(Jérôme Petazzoni) #7

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/


(Senyor) #8

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.


(Javanyou) #9

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

(Tekne) #10

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


(Mchu4sac) #11

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?


(Mchu4sac) #12

@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


(Mchu4sac) #13

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


(Alejandrovelez7) #14

@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!