Machine Learning Model on Docker

Machine Learning Model on Docker

So, today we are going use machine learning model in a docker container by installing the prerequisites inside the container i.e. Python and some required libraries and copy the model in the container.

Let's get started:

First we will start the Docker and download the CentOS Image in our VM. In many of my previous blogs I have installed and used docker so we are going to skip that part.

To download the Docker CentOS image run the following command:-

docker pull centos

image.png

Now we launch the Docker container by command:

docker run -it --name <container name> centos

Screenshot 2021-05-30 205348.jpg

Now, we will need the prerequisites to run our machine learning model. we install python and libraries like joblib, scikit-learn etc.

Screenshot 2021-05-30 210038.jpg

Screenshot 2021-05-30 210206.jpg

Screenshot 2021-05-30 210413.jpg

To use our model in the container we will have to train the model, whether in the base OS of our VM or somewhere else.

KHbVSaurH.jpg

Now the saved model has to be copied into the docker container by using command like:

docker cp <model_name> <container_name>:/<model_name>

Then we will use the machine learning model to predict in the container.

HQCSt7RGO.jpeg

we can see it is working fine, sane can be done for more complex machine learning models.

Thank You.