Web Application: Iris dataset classification web application
In order to deploy docker application, first of all we need to install Docker in our machine. We can download docker from https://www.docker.com/get-started . We need to have a full working of a web application so that we can dockerize the app. The step by step process followed is listed below:
- Create a new file without extension. Name it as ‘Dockerfile’. (capitalize the letter‘D’)
- Then we need to define our base image, from where we want to build our file. The base image I have used is ubuntu20.04 from Docker. We need to define it as:
FROM ubuntu:20.04
- To update all the packages of Ubuntu and upgrade them, we will define it as:
RUN apt update && apt -y upgrade
- Then, installing python3 in our image as :
RUN apt install -y python3-pip
- Create a requirements.txt file which contains all the required libraries to run the application.
- Copy the requirements.txt file from the machine to our Ubuntu base image (i.e from source to destination):
COPY requirements.txt ./requirements.txt
- Install the requirements.txt file in the docker image:
RUN pip3 install -r requirements.txt
- Then, expose the port to be used for running the application:
EXPOSE 8501
Overall the Docerfile contains the following commands:
FROM ubuntu:20.04
RUN apt update && apt -y upgrade
RUN apt install -y python3-pip
COPY requirements.txt ./requirements.txt
RUN pip3 install -r requirements.txt
EXPOSE 8501
By following the above steps, the setup for base image is done and we need to push it to the webserver of dockerhub. By doing so, we can pull it into our own webapplication’s Dockerfile. To do these process, the commands are listed below:
docker image build –t dipintimanandhar/ubuntum20cs020:v1 .
Output is shown as:docker image push dipintimanandhar/ubuntum20cs020:v1
Output is shown as:- Navigate to the folder to the web application file and created a new Dockerfile and add the following commands:
a. Pull the webserver image from the dockerhub’s repository
FROM dipintimanandhar/ubuntum20cs020:v1
b. Create a work directory where the server/local host runsWORKDIR /app
c. For building, copy the entire project into the containerCOPY . .
d. Create an entry point to make our image executableENTRYPOINT ["streamlit", "run"]
CMD ["Application.py"]
Overall the Dockerfile should contain the following commands:
FROM dipintimanandhar/ubuntum20cs020:v1
WORKDIR /app
COPY . .
ENTRYPOINT ["streamlit", "run"]
CMD ["Application.py"]
-
Build the docker image with the command :
build . -t dipinti123
Output is shown as: -
Creating a container:
docker run -p 8501:8501 dipinti123
We will start the web application in the url :localhost:8501
Output is shown as:
For learning application deployment for Machine Learning projects, I have created is a simple Iris dataset classification where we need to provide sepal length, sepal width, petal length, petal width in cm. The dataset used is imported from the sklearn.dataset. Logistic Regression algorithm is used for prediction. It will predict the plant type and its probability. The Web application is developed in Python3 and Streamlit is used to deploy it in web application. Streamlit is an opensource framework for building the Machine Learning related web application in a faster way.
--->Base image creation
--->Application.py
--->Dockerfile
--->Readme.md
The 'Base image creation' folder-> consists of the requirements.txt file, Dockerfile which is used to define our base image. This image has been pushed to webserver of dockerhub.
The Application.py is the Iris dataset classification Web Application. The Dockerfile is our web application Dockerfile
- Clone this repository
- Install docker and run it
- Navigate to the folder M20CS020
- Build docker image with the command
docker build . -t dipinti123
- Run the image with the command
docker run -p 8501:8501 dipinti123
- In your favourite web brower, access it with the url
localhost:8501
DIPINTI MANANDHAR M20CS020