Deploy Machine Learning Model on Docker

Docker has been a game-changer since its release in 2013. It has become a massively popular containerization technology.
Docker container technology was launched in 2013 as an open source Docker Engine.
Docker’s technology is unique because it focuses on the requirements of developers and systems operators to separate application dependencies from infrastructure.
For more about Docker click the link.
So , after this much of information let’s begin with the task.
In this task, we are simply going to make a Linear Regression Model on the Salary Dataset using Python where we estimate the salary according to years of experience.
And exciting thing is we will perform this task using Docker ……. 😄
We are going to do all our practicals in RedHat Linux Enterprise 8
Step — 1: Configuring Yum Repository for Docker

we have to created a docker-ce.repo
file and we have provided name, baseurl(official repository link), and gpgcheck. We disabled the software signature checking as we have provided the official link of Docker Community Edition.

Step — 2: Installing Docker Community Edition
using command
yum install docker-ce --nobest -y

Step — 3: Enabling the Docker Service in RHEL 8
using the command systemctl is-active do
Step — 4: Enable Firewall for Docker Engine
Before launching the containers on top of Docker Engine we have to make sure that the ingress and egress traffic is enabled for the Containers.
I had to enable masquerading. It looked like docker
already did this through iptables
, but apparently, this needs to be specifically enabled for the firewall zone for iptables
masquerading to work.



Step — 5: Pulling the Latest Centos Docker Image

"docker pull centos:latest "this command is we are going to use.
Step — 6: Create a Container with the help of docker image

Note:check the container it is started or not.

To attaché this container,

Step — 7: Installing Python and necessary libraries (numpy , pandas ,scikit-learn)
using command yum install python3

use following commands for libraries
“ pip3 install numpy”
“ pip3 install pandas”
“ pip3 install scikit-learn”

note:
In Container you need to copy/create machine learning model which you have created in jupyter notebook
-first of all you need to transfer file windows to linux with the help of the WINSCP tool, go to the internet and download
OR
You can mail this file to yourself ,login any browser on linux and download from there to your directry of linux.
Step 8: Now , copy the whole folder into the container with the help of the cp cmd
docker cp /hostfile (container_id):/(to_the_place_you_want_the_file_to_be)

Now attaché your container and create a python file and write code for Your respective model.
Here my model is for “salary prediction according to years of experience.”
I have used vim editor .if you don’t have vim editor then install it using command “yum install vim”


Step 9:now use “python3 file_name” command to implement your model.

and we are done!!!!😊
!!! Thank you !!!!!