How to Create Your machine learning and inside a docker container
The plan is like this ..
👉 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
Step 1:Decide what machine learning program you want to copy inside docker container and the dataset it require to get trained
Step 2: making the dockerfile
FROM centos
RUN yum install python38 -y
RUN pip3 install scikit-learn
RUN pip3 install pandas
RUN pip3 install matplotlib
COPY ml.py /home/
COPY SalaryData.csv /home/
CMD [“python3”,”/home/ml.py”]
explanation :
first we take the base container image for the dockerfile which here is centos
them we install python3 in that container image.
then we install scikit-learn , pandas, matplotlib module using pip command , inside the cotainer, in the lines ,
RUN pip3 install matplolib,scikit-learn,pandas,
then finally we COPY the program file from the computer to the container image ,and dataset also , using the COPY command , whose first parameter is from source , and then to destination.
Then we execute CMD command
CMD [“python3”,”/home/ml.py”]
to run the machine learning code inside the container whenever the container is deployed.
we build the code using docker build command , and assuming that all the required files are in the same folder and the pwd is inside the folder .
docker build -t whatever_your_tag:whatever_your _version .
the dot in the end tells where the Dockerfile file is located which in this case is the current directory.
Here is a screenshot for the working example of the code.