Installing and Running docker in a Docker container running in Openshift Installing and Running docker in a Docker container running in Openshift jenkins jenkins

Installing and Running docker in a Docker container running in Openshift


You have this article by @jpetazzo, from Docker team, about Docker In Docker (DinD):

article:

The primary purpose of Docker-in-Docker was to help with the development of Docker itself. Many people use it to run CI (e.g. with Jenkins), which seems fine at first, but they run into many “interesting” problems that can be avoided by bind-mounting the Docker socket into your Jenkins container instead.

DinD Repo:

This work is now obsolete, thanks to the combined efforts of some amazing people like @jfrazelle and @tianon, who also are black belts in the art of putting IKEA furniture together.

If you want to run Docker-in-Docker today, all you need to do is:

docker run --privileged -d docker:dind

So here is an article using another approach to build docker containers with Jenkins inside a docker container:

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

So you may want to adapt one of this solutions to your OpenShift scenario. I hope it solves your issue.


I am trying to setup a container in OpenShift that runs a Jenkins that is itsself able to run docker to make use of declarative pipelines where the build is running in it's own docker container. This basically makes it necessary to install and run docker inside this container.

I don't think your conclusion here is the only possibility, and what I'll describe below is an easier approach to get what (I think) you want! :) If there are any other use cases that you have than these 3 I'll describe, let me know and I'll try to update to cover them:

  • Pipelines running in their own containers
  • Running additional containers from Pipelines
  • Building container images from Pipelines

Pipelines running in their own containers

For this case, there's the excellent Kubernetes plugin.

With this plugin, you add a Kubernetes/OpenShift cloud to the Jenkins global config. This can either be the one in which Jenkins is running (if you use the Jenkins image provided by OpenShift, this gets added by default at least), or an external cluster.

Inside that configuration, you can define PodTemplates (again, there are a couple of examples provided in the Jenkins image provided by OpenShift), or you can specify that in your pipeline directly also I think. When your pipeline requests a node/agent with a label that matches one of these (and there are no long-running agents that match), then a pod will be created from that template, and your pipeline execution will happen inside a container in that. Once it's no longer needed, it will be deprovisioned again.

Here are the pipeline steps exposed by this plugin: https://jenkins.io/doc/pipeline/steps/kubernetes/

Running additional containers from Pipelines

As part of your pipeline, you may want to run some tests, and those may expect to be able to interact with e.g. a database. You can create resources for that in your OpenShift project (e.g. a Deployment & expose it with a Service), and tear them down after. The openshift-client plugin is very useful here and has docs on how to interact with OpenShift.

Building container images from Pipelines

If your goal is to build container images from pipelines, remember that OpenShift also exposes this capability (depending on the security configuration) through Builds. Just like in the previous section, you can use the openshift-client plugin to create and trigger builds.


For more information on the Jenkins image that's maintained by OpenShift (and generally how to do useful things in Jenkins on OpenShift), there's this dedicated page in the OpenShift docs.


You'll need a privileged pod running jenkins wich mounts the openshift node docker socket. This is a bad idea as jenkins'll launch container outside kubernetes semantics and control.

Why do not use s2i service shipped with openshift ?

Regards.