Task 1 :- Deploy ML model on Docker Container
Task Description 📄
👉 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 :-
Step 1 :- Installation and starting docker service
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 ..
Step 2 :- Pull docker image and run container
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
Step 3:- Create a workspace for code .
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 .
Step 4:- Install python and various libraries reqired for ml code in linux (docker host).
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.
Step 5:- Write code
use vim task1ML.py to create a file and start writing the below code.
Step 6 :- Run code in linux (docker host)
use python3 task1ML.py to run your ml code
Step 7 :- Split file in 2 files : one -training model python file , second -predict file
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
Step 8 :- Move the whole workspace into docker Mlos container.
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……