Deployment Of machine learning model on Docker Container

AYUSH BAJPAI
4 min readMay 27, 2021

Hello, welcome again, here I am going to deploy a machine learning model on the top of the docker container of the centos operating system. This is task 1 of my summer training at Linuxworld informatics. So , We are going to follow the following steps in our given task:

Task 01 👨🏻‍💻

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 the docker container

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

Pre-requisites: docker should be installed on your base operating system, in my case, I am taking Rhel 8 operating system.

So, let’s start off our task of deployment of machine learning Model:

👉Step 1:

First of all, we should check our docker is installed in the system or not. To check docker is installed or not,use the following command:

docker  -- version

As we can see docker is installed successfully in our system. so now move further

👉Step 2: Start the docker service

To start the docker service use the below command:

systemctl start docker

to check docker service started or not use below command:

systemctl status docker

Docker service started successfully.

👉Step 3: Pull the Centos Image

now as our service is started successfully now we have to pull the centos image from the docker hub.

command to pull centos image is given below:

docker pull centos:latest

docker images command tells us the no. of images present in our operating system. As we see our centos image is successfully pulled.

Step 4:Creating a container

The next step is to create a docker container. To create a container use the below command:

docker run -it --name c3 centos:latest

As we see our container is successfully launched. and its command prompt is now showing.

Step 5:

Install the Python software on the top of the docker container

to install the python software we are using the following command through the centos prompt:

yum install python3

Python 3 is installed successfully on our centos. next thing we need in our centos is the clear command .to get clear command we should use the following command:

yum install ncurses

now we will install the required libraries of our ML model in the centos through pip3 install command.

pip3 install pandas
pip3 install scikit-learn

Now we will move further and copy our dataset of the ML model to the RHel 8 through the use of the Winscp command. As I have copied it to my rhel8 as you see below:

To copy this file Book1.csv to the centos from the rhel8 I have used the following command:

docker cp Book1.csv c3:/

As you can see in the above image I have shown it.

Now you can file is successfully transferred to the centos.

Now to create a file in Centos we need vim. to get vim use the below command:

yum install vim

vim is installed successfully.

Step 6:

Now, We will create a Machine learning model in the centos and run it. I have written the code of the ML model in the ayush.py file.

to create a file :

Code of ML Model

now I have written the code inside the ayush.py file. now it’s time to run our Machine learning model in the docker container and predict the marks of an inputted student on the basis of hours he studied.

As we can see our Machine learning model is successfully run on the docker container. so our task 1 is successfully completed.

thanks for reading.

--

--

AYUSH BAJPAI
0 Followers

ansible learner,coding enthusiast,learning new technology