Deploying ML model on top of Docker container

Jyoti Pawar
4 min readMay 30, 2021

--

Hello friends!!!

Excited to know how can we deploy ML model on top of docker container??

So today we will see how’s this possible

Before this I would like to give you a short intro regarding what is ML and Docker.

Machine Learning:

Humans have a power of prediction based on the historical data they have. But with the large data including much more complex numbers in that , it becomes difficult to conclude/predict for the humans. So we take the help of computers i.e machines here.

Machine learning involves computers discovering how they can perform tasks without being explicitly programmed to do so. It involves computers learning from data provided so that they carry out certain tasks. For simple tasks assigned to computers, it is possible to program algorithms telling the machine how to execute all steps required to solve the problem at hand; on the computer’s part, no learning is needed. For more advanced tasks, it can be challenging for a human to manually create the needed algorithms. In practice, it can turn out to be more effective to help the machine develop its own algorithm, rather than having human programmers specify every needed step.

By Machine Learning we can predict any of the complex datas very easily.

Docker:

Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. By taking advantage of Docker’s methodologies for shipping, testing, and deploying code quickly, you can significantly reduce the delay between writing code and running it in production.

How to deploy ML model on Docker:

Here I have used the dataset which has salary of employees according to the years of experience they have.

  1. Installing docker:

Install docker using this command

yum install docker-ce — nobest

(There’s double hyphen before nobest)

2. Pull centos image from Dockerhub:

docker pull centos

3. Run the container and copy the Salary Dataset inside the container:

4. If you already have the container in the stopped state then start and attach it:

5. Install python3 inside container:

6. Install the necessary python libraries for ML — Pandas and scikit-learn:

7. Create the python script for training the ML model:

8. Run the script:

9. Create new script to load the trained model in it and predict the salary of employee by inputing the years of experience:

10. Run the script to predict the salary:

So, here we trained and deployed the ML model on top of Docker container and predicted the salary of employee.

GitHub link: https://github.com/jyotisp/simple_lin_reg

Hope this blog finds you interesting !!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Jyoti Pawar
Jyoti Pawar

Written by Jyoti Pawar

Devops || AWS || ML || Deep learning || Python || Flask || Ansible RH294 || OpenShift DO180

No responses yet

Write a response