Deploying Machine Learning Model in Docker

This article shows you how to train and deploy a machine learning model in docker.

Before starting,

Let's talk about Docker and Machine Learning

What is Docker?

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. By doing so, thanks to the container, the developer can rest assured that the application will run on any other Linux machine regardless of any customized settings that the machine might have that could differ from the machine used for writing and testing the code.

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 tutorial, am using VMware VirtualBox and RHEL 8 as the Operating System.

Here, we are going to run a machine learning model on top of the docker container.

Before doing that we need to install docker on top of the RedHat and also we need to configure the repository for the docker, then install centos 7 using the docker image.

To configure the repository for docker :

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

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

To install docker use the below command :

yum install docker-ce --nobest -y

Then start the docker service :

systemctl start docker

Check the status of docker :

systemctl status docker

To enable the service permanently :

systemctl enable docker

Now, we are ready to install centos on the docker.

Before that, we need to download the docker image of centos

To download the version centos 7 :

docker pull centos:7# this will download centos from the docker hub

To launch this os:

docker run -t -i centos:7

To train and deploy machine learning we need to install python on centos

yum install python3 -y

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

  • NumPy
  • pandas
  • scikit-learn

Now, we need to copy the DataSet file to the centos container in the root directory

Python Enthusiast