Deploying a Machine Learning Model in a Docker Container

Sri Raviteja
3 min readMay 27, 2021

Summer Program 2021 — #Task1

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.

We are provided with a dataset which is filled with historical data/ observations.

Dataset/observations

Step 1: Write a code to train the model and get a prediction
https://github.com/Ravenblaze128/Summerprogram-lw/blob/main/Task1/Salary_LinearRegression.ipynb

Step 2: Check if the Docker is available or not

docker info

if unavailable, use

yum install docker-ce

Step 3: Download CentOS latestimage from Docker Hub

docker pull centos:latest

Step 4: Create a Container with the help of CentOS image

docker run -i -t — name=<name> centos:latest

Step 5:Download Python in the Container

yum install python3

Step 6: Install the Necessary libraries for the Python

pip3 install numpy
pip3 install pandas
pip3 install scikit-learn

Step 7: Copy the ML Model from the host to the container

while at host, use below command twice to copy the model and .csv file, by changing the names.

docker cp <model_name> <container_name>:/<model_name>

Step 8: Create a Model file

log back to the container terminal by using the command

docker attach <ContainerName>

and open a vi editor with .py ext.,

Esc-> :wq to save & exit the editor

Step 9: Run the Model

Run the model by using the command,

python3 model.py

Type in the Number of years of Experience,

The result!!

That’s all Folks!

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

Sri Raviteja
Sri Raviteja

No responses yet

Write a response