flo.X
flo.X

Reputation: 23

Running Jenkins job with docker command on kubernetes cluster fails "docker: not found"

We are running a Kubernetes cluster for building Jenkins jobs. For the pods we are using the odavid/jenkins-jnlp-slave JNLP docker image. I mounted the /var/run/docker.sock to the pod container and added jenkins(uid=1000) user to the docker group on the host systems.

When running a shell script job in Jenkins with e.g. docker ps it fails with error docker: not found.

$ /bin/sh -xe /tmp/jenkins6501091583256440803.sh
+ id
uid=1000(jenkins) gid=1000(jenkins) groups=1000(jenkins)
+ docker ps
/tmp/jenkins2079497433467634278.sh: 8: /tmp/jenkins2079497433467634278.sh: docker: not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE

The interesting thing is that when connecting into the pod manually and executing docker commands directly in the container as jenkins user, it works:

kubectl exec -it jenkins-worker-XXX -- /bin/bash
~$ su - jenkins
~$ id   
uid=1000(jenkins) gid=1000(jenkins) groups=1000(jenkins),1000(jenkins)
~$ docker ps 
CONTAINER ID        IMAGE        COMMAND         CREATED         STATUS

What is doing Jenkins in its job differently? Same user, same container, only groups=1000(jenkins),1000(jenkins) lists 1000(jenkins) as group 2 times when connecting manually. What am i missing?

Upvotes: 2

Views: 887

Answers (1)

Rakesh Gupta
Rakesh Gupta

Reputation: 3780

/var/run/docker.sock is just the host socket that allows docker client to run docker commands from the container.

What you are missing is the docker client in your container.

Download the docker client manually and place it on a persistent volume and ensure that he docker client is in the system path. Also, ensure that the docker client is executable.

This command will do it for you. You may have to get the right version of the docker client for your environment

curl -fsSLO https://get.docker.com/builds/Linux/x86_64/docker-17.03.1-ce.tgz &&
tar --strip-components=1 -xvzf docker-17.03.1-ce.tgz -C /usr/local/bin

You may even be able to install the docker using the package manager for your image.

Upvotes: 2

Related Questions