Machine Learning operations over a Docker Container
In this Blog, We will train and run a machine learning model over a docker container with the least amount of resources and time using containerization.

So, This task is performed step by step:
- Download and install docker into the base OS
- Then Download and image from docker hub
- Launch a container
- Download and install python3 in container and also install pandas, numpy and sklearn library using pip
- Write the code to train the model
- Now Run the model
Step 1 > Install the Docker using command:
yum install docker-ce -nobest -y
To check docker is running or not.
systemctl status docker
Step 2 > run a command to pull image of CentOS (or as per your preference) from the docker hub over the internet:
docker pull centos: latest
Step 3 > Now, we will launch our docker container using the downloaded image.
docker run -it — name Task1 centos-latest
Step 4 > Then, We will install python3 in container .
yum install python3
and, also install pandas library,
pip3 install pandas
numpy library,
pip3 install numpy
and sklearn library.
pip3 install sklearn
Step 5 > Now, we create the code of python to train the model.
vi Salary_Predictor.py
Code >
import pandas
import numpy
db = pandas.read_csv(‘Salary.csv’)
y = db[“Salary”]
x = db[‘YearsExperience’]
x = x.values
x = x.values.reshape(-1,1)
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit( x, y)
years = int(input(“Enter your Years Experience to predict the Salary”))
Salary_approx = model.predict([[ years ]])
print(Salary_approx)
Step 6 > Now, At Last we will run the code:
python3 Salary_Predictor.py