MLOps: Deploying CNN model with Docker and Integration with jenkins.

Mukul Jeveriya
4 min readMay 30, 2020


In this project we gonna trying to achieve automation via Jenkins for creating a CNN(Convolution Neural Network) model with approx 90% accuracy.


1.Create container image that has Python3 and Keras or numpy installed using Dockerfile.
2. When we launch this image, it should automatically start training the model in the container.
3. Create a job chain of job1, job2, job3, job4 and job5 using build pipeline plugin in Jenkins

JOB1 : Pull the Github repo automatically when some developers push repo to Github.

JOB2: By looking at the code or program file, Jenkins should automatically start the respective machine learning interpreter which is installed in image container to deploy code and start training( eg. If code uses CNN, then Jenkins should start the container that has already installed all the softwares required for the cnn processing).

JOB3: Check accuracy, if accuracy is less than 85% , then trigger job4 for tweak the CNN model architecture and retrain the model. If it is greater than 85% then email to the developer.

JOB4: tweaking in CNN model.

JOB5 : Monitor the container where the program is running.

In this task i am creating a CNN model to predicting object in the dataset of 5 categories which are cat,dog,car,aeroplane,bikes.

Lets start!!!

Firstly i am writing a basic code for creating a CNN a model. In this i am created a basic architecture.If my model is not achieve the accuracy show tweaking job will happen and adding some more feature in my CNN model code.

Now i am creating a Docker image via Dockerfile.This image is for ,as i launch the container the interpreter open and code file run after code execute the container stop.

creating the image using command

#docker build -t imagename:v1 /dockerfile_path

This is my docker images cnnmodle:3 is image for our task

Now i am creating a git repo in my windows os where my CNN model code file and dataset exist.

For achieving automation we create a git post-commit file as soon as i commit my code in gitbash the code itself push to the github and start job1 of Jenkins.


I am copy all the files from github .


As job1 execute perfectly job2 trigger.this launch a docker container in which are CNN model code execute.

job2 configuration

in execute while launching the docker container we mount the path where our dataset and codefile copy from github on redhat to our docker image folder where our code execute.

Below is the epochs picture it took more the 4 hour to complete them

Accuracy while epochs are 5 in first time


In this job our aim to check our CNN model achieve the accuracy or not if it achieve so a email send to the developer else tweaking job gonna be run.


This job trigger after job3 build successfully i.e accuracy is less then 90%.this job tweak some code into the CNN code file and then post build the job2 again.

For tweak i am using sed command to add or over write on a particual line.

tweak code

After tweaking below is my model summary.

final model summary
accuracy after tweaking now epochs are 6

it tooks more then 7 hours to complete all 6 epochs.


This job check if accuracy is not achieved so docker container is running or not to achieve accuracy if not so this job trigger the job2 via curl command else accuracy achieve so no need to check.

GitHub link for dataset and code

This task took lots of time but the happiness after completing is out of the world. I hope this blog help you.

Thank you!!!