Deploying Machine Learning into Docker Container
TASK -01
Task Description :-
👉 Pull the Docker container image of CentOS image from DockerHub 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.
To perform this task we are using REDHAT LINUX(RHEL-8) as our Base OS for deploying machine learning model into the docker container and the dataset has been taken from the Internet.
Note: Kaggle is website where we can find many real-time datasets to work on.
STEPS TO COMPLETE THE TASK:
STEP - 1
Installation of Docker into RHEL-8
- # yum install docker -ce --nobest : is the command used to install docker in RHEL-8..
- To check if docker has been successfully installed use #docker info command
STEP -2
- Now we need to start the docker by using the command #systemctl start docker
- To check if our docker is running or not using the command #systemctl status docker
- By this we can see that Docker is actively running.
STEP-3
- Once the docker starts running, we need to pull the Docker container image of CentOS image from DockerHub and create a new container using the command #docker pull <image name:version>
- After this we need to run the docker container, the command used for it is #docker run -it --name <> centos. In this we need to give a name of our choice, I gave 'Salary', a new OS opens up.
STEP-4
Installing the Python software on the top of docker container using the command #yum install python
STEP-5
Once the python is installed , we need to install 3 libraries
- Pandas using #pip3 install pandas
2. scikit_learn using #pip3 install scikit_learn
3. numpy using #pip3 install numpy (numpy was already installed in my case)
After all these libraries have been installed , we need create a model in our container.
STEP-6
Now we need to create a directory in the container following the commands below ;
#mkdir /root/salary
#cd /root/salary
#ls
Once the directory has been created make sure to check if the dataset file has been saved in my case('Salary.csv') in the downloads directory in the main host OS(RHEL-8). Now copy that file location in the container using the command #docker cp / <source location> <container name/ID> <destination location>
This shows that the dataset has been stored properly
STEP-7
In this step we are going to train our model and to do so we need to provide a code to the OS by creating a file to type the code. The command used to ope the file is # vi <name>.py
A new text editor will be opened and we need to type our code in it using i:insert and to save and exit use Esc+:wq
To check if the file is running or not use #python3 <filename>.py
Once it runs properly ,we can test our model now.
STEP-8
To test the model we need to create one more file by using the command #vi<testingfilename>.py.
A new test editor will open up and we need to write the code shown.
After this we need to run this file using the same command #python3<testingfilename>.py and it will display the output.
In this step we need to enter the year of experience to check the salary from, I have given the input as 3 and the output has been displayed. By we can predict the salary based on the year of experience using a simple dataset
Therefore by following the above steps, we can deploy a machine learning model into docker container.
Thankyou for reading my blog. Hope you like it!
P.s : This is my very first attempt of writing a blog , I would appreciate if you drop in your suggestions so that I can enhance my writing skills futher :)
AIR 2495 GATE CS '24 | AIR 3661 GATE CS '23
3yWell done