Machine Learning Model Over Docker Container

Simple Linear Regression code run on docker container

I have used Dataset: Salary_Data.csv ( Click here to get the dataset )

As we need docker so, First let us configure docker and install it in our system.

Note: I have used RHEL8 operating system. You can use Centos or Fedora also.

Step1: Configuring repository for docker

Path: /etc/yum.repos.d/

[docker_ce]
name=docker
baseurl=
https://download.docker.com/linux/centos/7/x86_64/stable/
gpgcheck=0

Step2: Installing Docker

yum install docker-ce --nobest -y

Step3: Starting Docker services and making it Permanent

#Will start docker services.
systemctl start docker

Now, let us start the process to run the Simple Linear Regression code on the docker container. I have used centos image, to be specific centos:latest

Step1: Deploy Container

docker run -it --name ml_model centos:latest

Step2: Install necessary dependencies

  • Python Software
yum install python3 -y
  • sklearn python library
pip3 install sklearn
  • pandas python library
pip3 install pandas

Step3: Copy Salary_Data.csv Dataset into the container from the docker host

docker cp Salary_Data.csv c329c7e0d63c:/ml_ws
#Example
docker cp /home/(name)/(folder_name)/(file_name) (container_id):/(to_the_place_you_want_the_file_to_be)

Step4: Salary Predict Code

Now, Run the Code!

I have created a docker image named as rahul079/sklearn_centos , which you can just pull and run the code!

Step1: Pull the image from docker hub

docker pull rahul079/sklearn_centos:v1

Step2: Deploy container

docker run -it --name model_ml rahul079/sklearn_centos:v1

Step3: Run the Code!

cd ml_ws/
python3 model.py

Done! That Simple.

Thank You for Reading!

connect me :