Deploy machine learning model inside docker containers

What is Machine Learning?

Human brain is not much efficient in storing the tons of data so that it creates the patterns to recognize the things and learns new things by storing patters . The computers are good in storing the tons of data but do not have intelligence like human. Here the role of Machine Learning comes up . Machine Learning is branch of AI in which we program the model and train the model with the help of dataset which results in creation of pattern.
This pattern is actual intelligence develop by computer.

What is docker?

Docker is a set of platform as a service products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels.

Task Description :-

  1. Pull the Docker container image of CentOS image from DockerHub and create a new container.
  2. Install the Python software on the top of docker container
  3. In Container you need to copy/create machine learning model which you have created in jupyter notebook

Finally integrate the ready ML model and docker image .

Now, Lets see how to run the machine learning model inside docker image :

Here I am using RedHat Enterprise Linux 8 (RHEL 8) as my host OS. And CentOS as my base docker OS .

Hope you have Installed the docker .

Step 1 :- . Check the docker is installed properly by using command

“# docker info ”

Step 2:-Pull the CentOS image from docker-hub

“# docker pull centos:latest”

Step 3:- Create the container using CentOS image

“ #docker run -i -t — name =<container_name > centos: latest”

After running this command terminal get attach to the CentOS terminal.

For ensuring the OS installation run the “# ls ” command which shows files in root directory of CentOS

Step 4:- Install the vim editor

“# yum install vim”

step 5:- Now using vim editor we gonna create a shell file which contains all library installation commands.

By running the shell file we can install all the required libraries by using only one command. Interesting!!

Libraries required:-Python3 , numpy , padas , scikit-learn

For creating shell file using vim editor

“# vim <file_name>”

step 6:- Run the file (before running the file do not forget to give permissions to file using command “#chmod 777”

Step 7:- Check for the packages installed properly or not

Step 8:- Import the trained ML model in the CentOS

I have already trained the model . You can download it. Now cloning the model from git repository

Open the cloned repository.

Step 9:- Run the Machine Learning Model

Start the python3 console in terminal using “#python3 ” command and run the model

Use commands:

#model_name.predict( [ [ value] ])” …….Give number of years to model to predict the salary

#model_name.coef_” ………To print the coefficient value

#model_name.intercept_” ……To print the bias value

Now we have integrated the ML model with the docker, cool !!

Thank you!!



Curiosity driven learner :)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store