created by vedant jore

Deployment Of Machine Learning Model on Docker

VEDANT JORE
5 min readMay 29, 2021

--

This article is for developers and who have been passionate about technologies, now here we are going to deploy one machine learning model using docker container.

What are containers??

It is a technologies that allow you to isolate applications and package with their entire runtime environment. Usually used for development, testing and deployment with favorable communication of files . Container enables patching and scaling of applications with rapid deployment. They highly supportive to agile and devops infrastructure.

What are the benefits?

The primary benefit is efficiency and agility. They much lighter-weight to define, build and insight methods like omnibus software builds with full Virtual Machine images. It also includes Container technologies — CRI-O, Kubernetes, and Docker — help you to simplify, speed up, and orchestrate application development and deployment with basic architecture.

What is docker?

In simply words it is a tool designed to make easier to create, deploy, and run applications by using containers….

In this article we are going to make one simple linear regression model using a salary dataset and deploying it on our powerful tool i.e. docker to get an idea about power of docker.

Now we are going to do all our practical's and model creation in RedHat Linux Enterprise 8 (RHEL 8)

Step 1 ->> Configuring Yum Repository For Docker

As we can see that we have created a “docker12.repo” file and we have provided Id, baseurl(official repository link), and gpgcheck. U can check it out using “cat <ur docker repo name>”. We disabled the software signature checking as we have provided the official link of Docker Community Edition.

Step 2 ->>Installing Docker Community Edition

In order to install docker community version we are going to use

yum install docker-ce — nobest -y

In RHEL 8 and Fedora, yum work as a package manager. We have nobest option, which helps to skip any unsupported version of Docker Engine.

Step 3->>Enabling the Docker Service in RHEL 8

Now in order to start and enable our docker service we used commands as

systemctl restart docker

It’s useful to restart our docker service, then use

systemctl enable docker

This command helps us to enable the docker service so after rebooting the docker service will be available to us. we used another command to check the status of docker i.e.

systemctl status docker

Step 4->> Enable Firewall for Docker Engine

So before using container on the top of docker, we need to active ingress and egress traffic for the docker containers.

During inspecting network rules with iptables, I realized that the switch to nftables means iptables that is formed kind of an abstraction layer that only shows a small part of the nftables rules. That means most of the firewalld configuration not be applied outside the scope of iptables. So to do that we have to enable masquerade.

Step 5->> Pulling the Latest Centos Docker Image

Here in order to pull image of latest centos operating system in your docker from DockerHub. I am using

docker pull centos:8

8 means it’s version of centos

docker images

This command help to check whether this image is available or not in your local system.

Step 6->> Create a Docker Container

To creates a container name myos1of CentOs version 8. we need to start our container so for that, we will write the following command

docker run -it — name myos1 centos:8

And by this command we are now in our new operating system that is centos, you call it as operating system under operating system (i.e. nested os)

now in order to check the yum repolist contents in our new os, we use

yum repolist

Step 7->> Installing Python and Git in centos (i.e. in nested os)

To install python version 3.8 and git use following command.

yum install python38 git

now by using this command system can automatically download all required modules for python and git(dependencies)

Step 8->> clone our Python Code using git

We are going to clone our code by moving into our git repository

git clone <repository url>

Step 9->> Creating ml regression model’

I have already created regression model

model.py

Before running our program there is a need to install all the modules and dependencies.

to install all requirements just take a help of following command, it automatically install your all the dependencies.

pip3 install -r requirements.txt

Now we are going to execute our program with a Python3 Interpreter.

So here you can see that after executing our code automatically our model file is formed that is “SalaryModel.pkl”, now anywhere you can use that file in order to predict the result.

predict_salary.py

In the “predict_model.py”, we have loaded the pickle file i.e. “SalaryModel.pkl” and provided the User Input, and printed the result in an appropriate fashion, it used our machine learning code as a backend. After execution, it looks like this.

Bravo…we did, now we got our result…

Thanks for reading ..Stay Tuned For Next Article..

--

--