A Machine Learning Model inside the Container


In this article, I am going to show you how to create a machine learning model inside the docker.


  1. pull the centOS image from DockerHub
  2. Install the Python on the container
  3. Create the ML model inside Docker

Firstly, we have to check that the docker is installed or not so we will use this command.

To use docker we have to start docker services and I have used this command

Now, we have to pull the centos image from DockerHub by using this command.

To check if our os is download or not we use “docker images” command and to run the docker container we have used this command

Now we are inside our container and we have to install some software for running the ml model.

first, install the python by this command

Now we have to install the NumPy library

For loading the dataset we need pandas library so using pip3 we have to install pandas library

We have to install scikit-learn library to use linear regression .

We have installed all the library which is important to run our program

  • I have used WinSCP to transfer my data from window to RedHat

Now my dataset “Salary_Data.csv” is there in RedHat.And we can check by ls command

Now we have to send this file for our base os to docker by using this command. This command we have to write in our base os terminal.

Now Salary_data.csv is copied in the container and now we have to write our Machine learning code and also we have to train our model.

Now let's create a test.py

“vi test.py”

python3 test.py command will train the model

vi ml_model.py

The code can be found on GITHUB.





Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store