Machine Learning with Docker: Installation and Execution Guide

Sathvika Kolisetty
3 min readJul 7, 2023

In the realm of modern software development, Docker has emerged as a powerful tool for efficient and consistent application deployment. This blog will provide a detailed guide on installing Docker on the local virtual machine, setting up Python and pip, installing essential libraries like numpy, scikit-learn, and matplotlib, and finally running a machine learning model within a Docker container.

Step 1: Installing Docker on Your Local Virtual Machine

Docker enables efficient and isolated containerization of applications. Follow these steps to install Docker on your local virtual machine:

  • Update System Packages: Open a terminal and run the following command to update the system packages.
yum update -y
  • Add Docker Repository: Add the Docker repository to your system by running the following command.
yum-config-manager --add-repo
  • Install Docker Engine: Now, you can install Docker Engine using the following command.
yum install docker-ce -y
  • Start and Enable Docker Service: After the installation, start the Docker service and enable it to start on boot.
systemctl start docker
systemctl enable docker

you can check the status of docker by the following command

  • Docker Installation: To verify that Docker is installed correctly, run the following command. If Docker is installed properly, it will display the version information.
docker --version

Step 2: Installing Python, Pip, and Required Libraries

Python and pip are essential tools for developing machine learning models. You can use package managers like apt-get to download python3 and pip. After installing Python and pip, open a terminal or command prompt and run the following commands to install the required libraries.

Installation of required libraries
pip3 install numpy
pip3 install matplotlib
pip3 install scikit-learn

Installation can be verified by using the following command

pip3 list
Installed python modules

Step 3: Running a Machine Learning Model in Docker

Copy machine learning model files and any other dataset files, into the / directory on the docker container from the host machine. Now, run the python file which consists of the model. The output of the model will be displayed in the terminal. In this practical, I created one Linear Regression model to predict the marks based on the number of hours you study. I will use the trained model to deploy on Docker and predict the output.

output of the model

Docker provides a robust and efficient environment for deploying applications, including machine learning models. In this blog, we covered the step-by-step process of installing Docker on your local virtual machine, setting up Python and pip, installing crucial libraries (numpy, scikit-learn, matplotlib), and running a machine learning model within a Docker container.

Thank you so much for reading:)