How to allow Jenkins to call docker out of the container

1/21/2019

I have locally installed OpenShift platform. Jenkins has been deployed there as a dockerized application. I need to call Docker during Jenkins job executing to perform some base Docker operations: build, push, pull.

Unfortunately Docker is not reachable out of the Jenkins container.

$ oc exec -it jenkins-1-cdjdx -- /bin/bash
$ docker
bash: docker: command not found

As far as I understood I have to install the Docker plugin and perform a new cloud item for Jenkins global settings. So I would try to describe Docker as a new cloud item but unfortunately I don't know how to define a Docker Host URI and a port.

-- Kanunik Dmitriy
docker
jenkins
kubernetes
openshift

1 Answer

1/21/2019

Docker plugin will not install docker to the container, it will just add docker support to Jenkins.

You need to install docker client inside a Jenkins container. I don't know which image you use, but hope you will find a right way of how to do it.

Than, you have 2 ways of how to make it works:

  1. Attach docker socket from a host machine to your container. It means, you need to mount hosts' /var/run/docker.sock to the same path in the container. In OpenShift you also can use exposeDockerSocket option for a build strategy, but I don't think you use that feature here. But if you run it as a general pod, you need to mount it using "hostPath" volume. Also, I think you will need to modify security policy, check that question.
  2. Run independent Docker right in your container, that mode named Docker-in-Docker. You can google it, but I think the first option is better in your case.
-- Anton Kostenko
Source: StackOverflow