Using Machine Learning Model in a Docker Container

Using Machine Learning Model in a Docker Container

So, today's task is to:-

  • Pull the Docker container image of CentOS image from DockerHub and create a new container
  • Install the Python software on the top of the docker container
  • In Container you need to copy/create a machine learning model which you have created in Jupyter-notebook

Let's start:-

Step 1:-

Download the dataset and create the Machine Learning Model:-

Here I'm using the salary dataset and the model will predict how much salary you will get.

Dataset:-

Dataset.jpg

Python Jupyter Notebook:-

jupyter-1.jpg jupyter-2.jpg

model created.jpg

As you can see our model is created, let's move to the next step.

Step 2:-

Now let's move this model to our virtual machine, I will use WinSCP to transfer the model file to the virtual Linux if you use other software like FileZilla , etc, you can use those also.

Just open the WinSCP, enter the IP address of VM, enter the password and the files of VM will open on the right side of the window whereas the left side will have the windows files. Just drag the model from the left side to the right side of the VM and the file will transfer from windows to VM.

winscp.jpg

Step 3:-

Now let's start the Docker and download the CentOS Image from Docker hub in VM.

In various previous blogs I've demonstrated how to download Docker so, to set up the Docker repo and downloading Docker please refer to this blog. Here I'm gonna directly download the centOS image.

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

docker pull centos

By default, it will download the latest image from the Docker hub. downloading centos.jpg Here CentOS image is already installed in my VM so it is showing me this message.

Now run the Docker container simply by running:-

docker run -it centos

container started.jpg Here you can see our Docker container is started.

Step 4:-

Now we have to copy the model from our base OS to the Docker container. We can simply copy the model by using:-

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

copying from os to container.jpg

This will copy the model into the Docker container. If you don't know your container name you can check by running:-

docker ps

it will show you all the running containers. saving model in folder container.jpg

Here you can see our model is copied in the Docker container.

Step 5:-

Now it time to test the model in the Docker container but first we have to install the dependencies like Python and its libraries like joblib scikit-learn , etc.

You can install Python by using yum after which you can install libraries by using pip3 command. python installed.jpg download joblib.jpg installing scikitlearn.jpg

Step 6:-

Now let's test the model:- model working fine.jpg

As you can see our model is working fine means our task is complete.

I would like to thanks Vimal Daga sir for providing us with the knowledge required to complete this task.

Thank You