Creation of a docker image intended to be used for deploying Java applications into OpenShift (Red Hat’s public cloud application development and hosting platform that automates the provisioning, management and scaling of applications).
The official Dokerfile from Jenkins already has git but it lacks maven and oc tools. Therefore, let's extend it to include them.
Let's create a new Dockerfile file with content:
FROM jenkinsci/jenkins:ltsUSER rootRUN apt-get updateRUN apt-get install -y mavenRUN apt-get install -y wgetRUN rm -rf /var/lib/apt/lists/*RUN wget https://github.com/openshift/origin/releases/download/v1.5.0/openshift-origin-client-tools-v1.5.0-031cbe4-linux-64bit.tar.gzRUN mv openshift-origin-client-tools-v1.5.0-031cbe4-linux-64bit.tar.gz /opt/RUN tar -zxvf /opt/openshift-origin-client-tools-v1.5.0-031cbe4-linux-64bit.tar.gz -C /opt/RUN rm /opt/openshift-origin-client-tools-v1.5.0-031cbe4-linux-64bit.tar.gzRUN echo 'export OC_CLIENT=/opt/openshift-origin-client-tools-v1.5.0-031cbe4-linux-64bit\nexport PATH=$OC_CLIENT:$PATH\n' >> /etc/bash.bashrcUSER jenkinsdocker build -t ib/jenkins_oc .Once command completes successfully, let's check the new image 'ib/jenkins_oc':
$ docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEib/jenkins_oc latest eb8487a11e20 6 minutes ago 1.03GBdocker run -p 8090:8080 -p 50000:50000 -v /srv/jenkins_home:/var/jenkins_home --name jojenkins1 ib/jenkins_ocThe docker image exposes jenkins http on port 8090 and it persist jenkins configuration on the host machine at the previously created directory '/srv/jenkins_home'.
From a browser in the host machine:
http://127.0.27.27:8090and enjoy it creating your jobs that retrive Java source code from git, package it with maven and deploy it to OpenShift cloud.