Deployment of Streamlit App on Docker Container
What is Streamlit?
Streamlit is a free and open-source framework to rapidly build and share beautiful machine learning and data science web apps. It is a Python-based library specifically designed for machine learning engineers. Data scientists or machine learning engineers are not web developers and they're not interested in spending weeks learning to use these frameworks to build web apps. Instead, they want a tool that is easier to learn and to use, as long as it can display data and collect needed parameters for modeling. Streamlit allows you to create a stunning-looking application with only a few lines of code.
Why should data scientists use Streamlit?
The best thing about Streamlit is that you don't even need to know the basics of web development to get started or to create your first web application. So if you're somebody who's into data science and you want to deploy your models easily, quickly, and with only a few lines of code, Streamlit is a good fit.
One of the important aspects of making an application successful is to deliver it with an effective and intuitive user interface. Many of the modern data-heavy apps face the challenge of building an effective user interface quickly, without taking complicated steps. Streamlit is a promising open-source Python library, which enables developers to build attractive user interfaces in no time.
Streamlit is the easiest way especially for people with no front-end knowledge to put their code into a web application:
What is Docker?
Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. By taking advantage of Docker’s methodologies for shipping, testing, and deploying code quickly, you can significantly reduce the delay between writing code and running it in production.
What can I use Docker for?
Fast, consistent delivery of your applications
Docker streamlines the development lifecycle by allowing developers to work in standardized environments using local containers which provide your applications and services. Containers are great for continuous integration and continuous delivery (CI/CD) workflows.
Consider the following example scenario:
Responsive deployment and scaling
Docker’s container-based platform allows for highly portable workloads. Docker containers can run on a developer’s local laptop, on physical or virtual machines in a data center, on cloud providers, or in a mixture of environments.
Docker’s portability and lightweight nature also make it easy to dynamically manage workloads, scaling up or tearing down applications and services as business needs dictate, in near real time.
Running more workloads on the same hardware
Docker is lightweight and fast. It provides a viable, cost-effective alternative to hypervisor-based virtual machines, so you can use more of your compute capacity to achieve your business goals. Docker is perfect for high density environments and for small and medium deployments where you need to do more with fewer resources.
How to install streamlit:
Make sure latest Python version and pip package installer are pre-installed in the environment. Use the below command to install Streamlit:
Recommended by LinkedIn
pip install streamlit
To test the installation is working:
streamlit hello
Streamlit's Hello app should appear in a new tab in your web browser!
Dockerfile for Streamlit app
FROM python:3.7
LABEL maintainer="vijaytanu766@gmail.com"
RUN apt update && apt-get update && apt full-upgrade -y && apt-get autoremove -y
RUN pip3 install pillow && pip3 install streamlit && pip3 install requests
WORKDIR /
EXPOSE 8501
COPY frontend.py /
COPY Video /
ENTRYPOINT ["streamlit", "run"]
CMD ["frontend.py"]
To create an Docker image from the above dockerfile use the below command:
docker build -t <image_name:tag> <Dockerfile location>
docker build -t streamlit_app:latest .
To run the docker image use the below command:
docker run -dit --name <container_name> <image_name:tag>
docker run -dit --name streamlit_container streamlit_app
The Final Output:
GitHub link for the code reference :
Thank You for Reading my Article.......
Amazing working 👍