Machine Learning Model inside Docker

Shubham Kumar
5 min readMay 29, 2021


What is Machine Learning?

In simple words, Machine Learning is the concept which includes different types of algorithms through which we provide intelligence to a machine to work/predict something on itself on a particular dataset

What is Docker?

Docker is a platform in which it provides various operating systems so that the manual time required to install an operating system and then log in as a user and after that we open an application, is reduced to seconds with the use of docker as it provides operating system then and there and downloads it and installs within seconds

First of all we will upload our machine learning model file and dataset file on Github so that it makes easy for us to fetch the files from there with the help of cloning

We will open Redhat Linux in our VM and through ifconfig command , will note the IP of our user in Redhat

Download and install Putty(Generally used for connecting with another operating system and SSH provides a secure, encrypted connection to the remote system) and then type the IP which you noted in the previous step

After that it will open a terminal in which it will prompt for the username and password of your Redhat Linux user, enter it and then your redhat system will be opened in this terminal, prompting with

[root@localhost `]#

Create a workspace for yourself, here I have done the same by creating a directory named as ML for cloning the files from github

Clone the necessary files for running our model from github repository to the ML directory

Here we can see that .csv file as dataset and .pk1 as our model has been successfully copied in our ML directory

Now, we will focus on installing docker on our system

Navigate to /etc/yum.repos.d for creating a docker.repo file so that when we provide command for docker installation as yum install docker-ce then the system will check in yum.repos.d in all the .repo file for the url for downloading and installing docker from that url

Installing vim editor for writing code inside docker.repo file

Create a file with

vim docker.repo

Inside docker.repo , write the above codes for successful installation of Docker and save the file with pressing Esc and then :wq

command for installing Docker and after that docker will be successfully installed in your Redhat

Start Docker

Use the command docker pull with os_name for installing the particular os/container or pulling the image file of that particular os/container, here I have pulled centos os

For running the os and giving name to the os as skos

Checking the os has been successfully installed or not

Now you are successfully inside your container/os

Install python with the above code inside your container/os

Install numpy, pandas & scikit-learn libraries from python for successfully training your machine learning model

Now copy your file required for machine learning model inside docker container using the following command

docker cp file_name os_name:/directory_path

checking for successful copy of files

Here I have created a python file for running my machine learning model


code for running my model, here I have imported my model “salary.pk1” through joblib library and then saved it

Run the python file and here as you can see, my machine learning model is working perfectly fine and predicting the result for 15 years experience

Thankyou for visiting my blog, if you have any queries you can dm me on Linkedin and do like and comment your views after reading this blog 😃