๐ง Deploying Machine Learning Models inside Docker Containers ๐ณ
๐๐ฒ๐น๐น๐ผ ๐๐๐ฒ๐ฟ๐๐ผ๐ป๐ฒ, ๐ ๐ฎ๐บ ๐ฏ๐ฎ๐ฐ๐ธ ๐๐ถ๐๐ต ๐๐ฒ๐ ๐ฎ๐ป๐ผ๐๐ต๐ฒ๐ฟ ๐๐ฎ๐๐ธ ๐ผ๐ฟ ๐ฐ๐ฎ๐ป ๐๐ฎ๐ ๐ฝ๐ฟ๐ผ๐ท๐ฒ๐ฐ๐ ๐ฎ๐ฏ๐ผ๐๐ โ๐ง๐ฟ๐ฎ๐ถ๐ป๐ถ๐ป๐ด ๐ฎ๐ป๐ฑ ๐๐ฒ๐ฝ๐น๐ผ๐๐ถ๐ป๐ด ๐ ๐ฎ๐ฐ๐ต๐ถ๐ป๐ฒ ๐๐ฒ๐ฎ๐ฟ๐ป๐ถ๐ป๐ด ๐ ๐ผ๐ฑ๐ฒ๐น๐ ๐ถ๐ป ๐๐ผ๐ฐ๐ธ๐ฒ๐ฟ ๐๐ผ๐ป๐๐ฎ๐ถ๐ป๐ฒ๐ฟ๐ถ๐๐ฎ๐๐ถ๐ผ๐ปโ
To know more about docker and how to setup on RHEL8. You can refer my previous Blog.
Hope you have referred above blog and understood ๐๐ผ๐ฐ๐ธ๐ฒ๐ฟ.
Now Lets Move and understand about ๐๐๐๐ก๐ข๐ง๐ ๐๐๐๐ซ๐ง๐ข๐ง๐ .
Machine Learning :-
Machine learning is a method of data analysis that automates analytical model building. It is a branch of artificial intelligence based on the idea that systems can learn from data, identify patterns and make decisions with minimal human intervention.
In data science, an algorithm is a sequence of statistical processing steps. In machine learning, algorithms are โtrainedโ to find patterns and features in massive amounts of data in order to make decisions and predictions based on new data. The better the algorithm, the more accurate the decisions and predictions will become as it processes more data.
Some more concepts about ๐๐ผ๐ฐ๐ธ๐ฒ๐ฟ.
Dockerfile :-
Each Docker container starts with a Dockerfile. A Dockerfile is a text file written in an easy-to-understand syntax that includes the instructions to build a Docker image . A Dockerfile specifies the operating system that will underlie the container, along with the languages, environmental variables, file locations, network ports, and other components it needs โ and, of course, what the container will actually be doing once we run it.
Docker Image :-
Once you have your Dockerfile written, you invoke the Docker build utility to create an image based on that Dockerfile. Whereas the Dockerfile is the set of instructions that tells build how to make the image, a Docker image is a portable file containing the specifications for which software components the container will run and how.
So What is the Task Requirement :-
- 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
Lets do something more here by creating ML ready image using Dockerfile.
Hope you have already installed and started docker service. if not refer above given blog for reference.
First lets create new workspace in system.
Step 1:-
First of all to make Machine learning model we require some Dataset to work on. In this step clone my github repository where i have already provided required dataset.
command :- git clone <URL>
Step 2:-
Now as we have datasets lets create some python Ml code. Create a new file and write below code
Note :- Create this file in the current directory and not in / directory.
In this Code I have just created a Linear Regression Model to predict Salary of employees on the basis of their Experience. So here I have used scikit-learn library and then from sklearn.linera_model I have used LinearRegression function.
Step 3 :-
Now the next step is to create Dockerfile with some docker commands/instructions to create our own new image.
Note :- Create this Dockerfile in /ml directory.
Step 4 :-
We are almost done with everything and Now we are going to Build the image from the Dockerfile using buid command.
command :- docker build -t salaryapp .
Note :- Here โ.โ means current directory as we have our Dockerfile in same folder.
Step 5 :-
After Creating Image we have to run it or launch containers using run command.
command :- docker run -it salaryapp
Note :- -it means interactive terminal i.e we are telling our container to give some terminal to interact
So the app finally looks like this so container automatically starts and run code and give us interactive terminal to interact,
As soon as our program finishes the container automatically stops.
GitHub Link :-
the-helel/MlSummer (github.com)
Hope you understood the concept and performed this task with me.