Machine Learning Model inside a Docker Container

Aakash Choudhary
2 min readMay 31, 2021

--

Hello Everyone…

Machine Learning Inside Docker Container

In this technical world we have a lots of interesting and powerfull technologies and such these technologies become more powerfull on integration.

We are going to the power of Docker , Machine Learning and Python. In this blog i am going to tell you how to run a machine learning model inside a docker container. Let me tell you how we can do it step by step…

Step 1:

For creating a Machine learning model you need a dataset to work on. I have used a dataset which contains the record of Some employes and their salary. On the basis of this dataset we are going to train our dataset. All the required code and dataset is available on my github account. You can use your own dataset and functions to train your machine learning model.

Step 2:

Prerequisite:

  1. Linux Operating system on the top of virtual box or cloud. ( In my case redhat linux )
  2. Docker or podman or any containerisation tool. ( In my case Docker )

Now start Docker Services if not started..

=> systemctl start docker

Pull any container image … ( In my case Centos )

=> docker pull centos

3. Launch a docker container…

=> docker run -it — name mymodel centos

Step 3:

Now when you are inside a docker container , you need to install Python and related libraries as per the requirement of your model.

  1. yum install python3 -y
  2. pip3 install pandas
  3. pip3 install scikit-learn

Copy your dataset inside docker container…

4. docker cp SalaryData.csv mymodel:/

Create your Python file for model or copy that if already created. For creatinng a new file you can use touch or cat or vi command.

Run your python file…

5. python3 ML.py

Now you can see it works, your model is in action…

Hurray…🎉

You can use the Same dataset for your practice , Link is given below…

If you liked the above blog, please clap and share it.

DM me on LinkedIn in case of suggestions/feedback/queries:

--

--

Aakash Choudhary
Aakash Choudhary

No responses yet