Deploy Machine Learning model on Docker Container

Once the Machine Learning model is created then we need to deploy it somewhere so that our client can use it but how? So in this blog, I am going to explain to you how you can deploy your Machine Learning model on a Docker container, and later you can integrate it with Mobile Apps or Web Apps for your users to use it.


For this practical, I have created one Linear Regression model to predict the salary based on the years of experience and then I have saved the weight and bias in a file. Now I will use the trained model to deploy on Docker.


Once the instance is up copy all the code and model to the instance with the help of WinSCP or SCP command.

Step 1: Install Docker software on Host Operating System.

First, we need to install docker software so that we use the docker service to launch the container, and for this, we can use the yum command.

yum install docker -y

Now start and enable the docker service so that we can use docker to launch the container.

systemctl start docker

systemctl enable docker

As the docker service is running now so we can use docker to create a container image and also launch the container with the image.

Step 2: Create a customized docker image with our application and saved model

Here is the code of Dockerfile to create a container image.

I have used centos:latest image as a base image and also I have made / as the working directory. Then I have installed the required packages and library for the python code to load the model to predict the salary. Also in CMD, I have written the command to run the python code to predict the salary. So whenever the container will be launched it will code to predict the salary.

Now let’s run the docker command to build the image.

docker build -t model:v1 .

Now as the image is created so we can launch the container to use the salary prediction application.

Step 3: Launch container to predict the salary

docker run -it — name modelos model:v1

Here I have created one CLI Application that will ask for the experience in years and will predict the salary. But we can use a similar approach to use the model with the Flask app to create Rest API which can be used by Web Apps or Mobile Apps.

You can check my GitHub repository to get the complete code of the model, Salary prediction CLI Application, and Dokerfile.

GitHub Link:

Thank You for reading!! 😇😇

I'm passionate learner diving into the concepts of computing 💻