Creating Machine Learning Model on Docker Container

Aman Dev Verma
3 min readMay 27, 2021



Docker is an open source platform for developers and system administrators to build, ship, and run distributed applications based on Linux containers. Docker enables you to separate your applications from your infrastructure, so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. By taking advantage of Docker’s methodologies for shipping, testing, and deploying code quickly, you can significantly reduce the delay between writing code and running it in production.
By including libraries and other dependencies, applications can be transferred from one machine to be easily run on another.
Because Docker makes use of the Linux kernel housed on the machine it’s running on, regardless of any differences or customized settings, so long as any non-native elements are included within the package, your applications will run on any Linux machine. This means developers are more able to focus on coding without having to build around a specific system.

Features of Docker
➡️ An isolated, rapid framework.
➡️ An open source solution
➡️ Cross cloud infrastructure
➡️ Moderate CPU/memory overhead
➡️ Fast reboot

Task Description:

👉 Pull the Docker container image of CentOS image from Docker Hub 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

Before we start, first we have to set up our OS and configure yum and docker on it.

#yum install docker-ce — — nobest -y

Now we are done with installing docker.

We will start the task now.


Start docker and pull the centOS image. Then launch a new container in docker using that image.

#systemctl start docker

#systemctl enable docker

#systemctl restart docker

Now we will pull the image and launch the new container.

#docker images

#docker pull centos:8

#docker run —it — — name task1 centos:8


We will now install python and some packages in our docker container.

#yum install python3

#pip3 install pandas

#pip3 install numpy

#pip3 install scikit-learn


We will transfer the dataset from windows to our VM host using WinSCP.


Create python file.

Write the below code in that file.


Create a file in the docker container using the touch command in which the dataset has to be copied.

#touch SalaryData.csv

From host copy SalaryData_csv to docker container.

#docker cp <source path> containerid:/<file or folder name>


Run the python file.