How to: CI/CD with Docker, Jenkins, Openshift


  • git repo – code base created
  • docker repo  – project repo created
  • jenkins platform – with the pipeline,openshift addon
  • openshift platform – project with oc login, imaging pulling access

in codebase:

  1. create a Dockerfile for the base image installing only the needed libraries and tools.
  2. create a Dockerfile for the actual code base from git repo.
    1. calling from the base image
    2. script to install dependencies
    3. expose the right ports 8080 for server

in Jenkins:

  1. create a custom project for the base image. define the image path and give it a tag as base.
    1. get the git report with the base dockerfile.
    2. Call docker build the image with dockerfile and tag location.
    3. Then call docker push into the docker repo.
  2. create a pipeline for building the codebase. define the image path and give it a tag as the dev or production. Create node for the process, and then create stages for the different parts.
    1. stage clean the existing files locally.
    2. stage run unit tests and additional stages for integration acceptance tests
    3. stage for call docker build the image with dockerfile and output location.
    4. stage for call docker push to the docker repo.
    5. emailing or other post build clean ups
  3. create a project for deployment using the jenkins node docker-oc
    1. define the docker image path and tags from codebase docker repo
    2. login oc , and oc project
    3. import the docker image path into the OSE3 project with a tag name
      • if its first time, create-new app with the image path and the app name.
    4. logout oc when done
  4. link all these parts together into a bigger pipeline or emailtxt if preferred.

In Openshift3:

  1. if creating the app from the Jenkins pipeline CLI, then go to step2.
    • For sample project, create a project from the templates. change deployment from git to use image stream tag.
    • go into the deployment and edit the yaml file.
      1. for the parts(2 of them) that is listening “on change” for image, make sure it is pointing the imported docker image from the jenkins step
      2. we dont need a build process since thats done with docker
      3. make sure the services and routes are active. expose port same as the pod’s port
  2. Verify that the Jenkins step pushed a new image stream into the project
  3. new apps should trigger to build with the oc rc replication controller
  4. create new routes to expose the app, make sure the code base/docker image is exposing the same port number. default for OSE is 8080

DB storage within OSE3:

  • for example if you want to create an instance of mysql into OSE. you can only access the db directly through the Pod’s IP when running the app on the server.
  • If you need to work on it locally. You should OC login to the project, then do port forwarding to your machine. While the port-forwarding is still active, you can then access the db through localhost.

run the Jenkins steps should automatically build and deploy the image to OSE3 with a live server.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s