Task 1 :- Deploy ML model on Docker Container

👉 Pull the Docker container image of CentOS image from DockerHub and create a new container

👉 Install the Python software on the top of docker container

👉 In Container you need to copy/create machine learning model which you have created in jupyter notebook

Here are the steps we follow to achieve the above goal :-

Check whether the docker software is available using cmd rpm -q docker-ce .If not, then use yum install docker-ce — nobest -y to install software.

Now check whether the docker service is running or not using cmd systemctl status docker .If service is not running ,then start docker service by running systemctl start docker cmd. Again recheck whether service started using systemctl status docker cmd.

Docker service is running ..

use docker pull centos:latest cmd to pull the centos image from hub.docker.com . Syntax of this command is :-

docker pull image_name:version

check image is pulled successfully using cmd docker images

Run the container using cmd

docker run -it — name os_name image_name :version

use mkdir to create a directory named test1

We have salary dataset with fields salary and yearsExperience in this directory . Use the dataset u want.

Our goal is to calculate the salary based the years of experience value we provide .

In the above image we use cmd yum install python36 to download and install python3 in docker host .

In the below figure can see python36 software successfully installed .

First check whether pandas is installed or not using cmd pip3 list |grep pandas

If not installed then use :- Install pandas using pip3 install pandas to install it.

First check whether sklearn is installed or not using cmd pip3 list |grep sklearn

If not installed use :- Install sklearn using pip3 install sklearn cmd to install.

First check whether joblib is installed or not using cmd pip3 list |grep joblib

Install joblib module using pip3 install joblib

Here joblib already installed no need to install it.

use vim task1ML.py to create a file and start writing the below code.

Continue code…

use python3 task1ML.py to run your ml code

file 1 :- same code as written in above figure just remove the code related to predict operation into another file.

file 1 :- code

Run code using python3 task1ML.py

After running we can see that SalaryEstimate.pki file also created in our workspace due to joblib model.

File 2 :- predict.py code

Run predict.py using cmd python3 predict.py

docker start Mlos to start the stopped container .

Use docker attach Mlos cmd to go inside the started Mlos container.

Make workspace inside container named SummerTask using cmd mkdir SummerTask

Install python36 software as well as libraries(sklearn,pandas,joblib) that we install above in linux (docker host ). Same way we will install this libraries take help from upside or in below figures I have installed see there.

See the workspace whole path using cmd pwd after going inside the workspace

Use docker ps cmd to see the id of Mlos container.

Now in linux run cmd docker cp [src_path_linux_ws] container_id:[dest_path_ws]

Whole task1 directory copied inside the task1 directory in SummerTask directory in container.

Go inside SummerTask > task1>task1> in Mlos container

Here we will get all the files

Now run predict.py using cmd python3 predict.py

So our model model is launched inside docker container.

Thank you for reading……



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