Training and Deploying Machine Learning Model in Docker Container

suyog shinde
3 min readMay 26, 2021

What is 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.

What is Machine Learning?

Machine learning is a method of data analysis that automates analytical model building. It is a branch of artificial intelligence based on the idea that systems can learn from data, identify patterns and make decisions with minimal human intervention.

In this article, we are going to run machine learning code on top of the docker container.

I am using an AWS EC2 instance here.

First, let’s install python

yum install python36 -y

Configure the repository for docker:

Create a file “/etc/yum.repos.d/docker.repo”

[dockerrepo]
name=docker repo baseurl=https://download.docker.com/linux/centos/7/x86_64/stable/
gpgcheck=0

Installing Docker :

yum install docker-ce --nobest -y

Starting the docker service:

systemctl start docker

Checking the docker service status:

systemctl status docker

The Docker service is running all fine now we are ready to launch the centos container

We are going to use Centos image and deploy a container.

docker run -it centos

It will pull the centos image and also launch the container.

Let’s Install python in the centos container

yum install python36 -y

We need to install some python libraries which we are going to use in the Machine learning code.

  • sklearn
  • pandas

Now we need to copy the “SalaryData.csv” file to the centos container in the root directory

docker cp SalaryData.csv 36404a31a44d:/

The SalaryData.csv is successfully copied.

Below is the salary prediction code:

Now let’s Learn this code

Above 74042.011800594 is the predicted value by our model.

Keep Learning !! Keep Sharing !!

--

--