Machine learning model on top of docker container

Sonipuru
3 min readMay 27, 2021

--

_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
👉 Create a blog/article/video step by step you have done in completing this task.
👉 Submit the link of blog/article or video

So in the first part we have to pull the docker container image of CentOS from docker hub and create a new terminal . So first let me explain you what is docker and we need containerisation .

Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and deploy it as one package.

We start the docker as:-

systemctl start docker

So we pull an CentOS image on top of docker by using command:-

docker pull centos:7

And run a terminal on it as:-

docker run -it --name PuruOS centos:7

Now we have to download python on top of docker container . We do it by using —

yum install python3

Now we have to create/copy our model that we have created in jupyter notebook to our docker container so first we transfer the file from our windows to linux through winscp . Winscp works on SFTP file transfer protocol. In this way we will transfer our marks.csv ,marks.pk1,salarydata.csv file to the document folder of our redhat linux.

Now we take these files from our documents folder of redhat linux to our docker container by using the command :-

docker cp <filename> <container_name>: location

Now we have to run our model. So for this we go inside our docker container again by :-

docker attach PuruOS .

And for our program we have to install some additional python library by using pip3 command as:-

pip3 install pandas.

And go to the location where we copied our files using cd command as:-

cd /home.

And start python there as :-

python3.

Now we have to write our code .

Now we had made a model here to calculate the salary of employee on the basis of years of experience. By using joblib module we had dumped our model as (salary.pk1).now we can use this model in some other terminal by using load function of joblib module as:

model = joblib.load(‘salary.pk1’)

--

--