March 25, 2022
Streamlit+Pipenv+Docker-Compose+Docker
In this tutorial, we are going to learn how to can do that. We will start with creating our virtual environment using Pipenv. Then we will…

By Alex Yucra
1 min read
In this tutorial, we are going to learn how to can do that. We will start with creating our virtual environment using Pipenv. Then we will create a basic report in Streamlit and finally we will dockerize this whole ecosystem.
Step by step:
- Creating virtual environment for our project using Pipenv
- Creating a StreamlitApp
- Creating Dockerfile for our StreamlitApp
- Creating docker-compose.yml file
- Starting StreamlitApp
- Running the whole ecosystem with docker-compose
Let's get started?
Creating virtual environment for our project using Pipenv
$ python3 -m pip install pipenv
activate virtual enviroment and install streamlit
$ pipenv shell
$ pipenv streamlit
Creating a StreamlitApp
create directory and file, to lift a more complex application check the streamlit documentation
$ mkdir www && cd www
# app.py
import streamlit as st
import streamlit.components.v1 as stc
def main():
""" Main App """
st.title("Analise e segmentação de mercados | DashBoard")
st.markdown('<img src="https://raw.githubusercontent.com/FortAwesome/Font-Awesome/6.x/svgs/solid/crown.svg" width="20" height="20"> Wellcome to Streamlit Dashboard', unsafe_allow_html=True)
if __name__ == '__main__':
main()# app.py
import streamlit as st
import streamlit.components.v1 as stc
def main():
""" Main App """
st.title("Analise e segmentação de mercados | DashBoard")
st.markdown('<img src="https://raw.githubusercontent.com/FortAwesome/Font-Awesome/6.x/svgs/solid/crown.svg" width="20" height="20"> Wellcome to Streamlit Dashboard', unsafe_allow_html=True)
if __name__ == '__main__':
main()Creating Dockerfile for our StreamlitApp
Create a Dockerfile file at the root directory
# Dockerfile
FROM python:3.9
RUN pip3 install pipenv
WORKDIR /www
COPY Pipfile Pipfile.lock ./
RUN pipenv install --system --deploy --ignore-pipfile
COPY . .
CMD [ "python","www/app.py" ]# Dockerfile
FROM python:3.9
RUN pip3 install pipenv
WORKDIR /www
COPY Pipfile Pipfile.lock ./
RUN pipenv install --system --deploy --ignore-pipfile
COPY . .
CMD [ "python","www/app.py" ]Creating docker-compose.yml file
Create a docker-compose.yml file at the root directory
# docker-compose.yml
version: '3'
services:
dashboard:
build:
dockerfile: ./Dockerfile
context: ./
ports:
- "8501:8501"
volumes:
- "./www:/usr/src/app/www:delegated"
networks:
- streamlit-network
networks:
streamlit-network:
driver: bridge# docker-compose.yml
version: '3'
services:
dashboard:
build:
dockerfile: ./Dockerfile
context: ./
ports:
- "8501:8501"
volumes:
- "./www:/usr/src/app/www:delegated"
networks:
- streamlit-network
networks:
streamlit-network:
driver: bridgeStarting StreamlitApp
$ pipenv shell
$ streamlit run www/app.py$ pipenv shell
$ streamlit run www/app.pyRunning the whole ecosystem with docker-compose
After all this is done, goto the terminal and into the root path where docker-compose.yml file has been created. Run the following command:
# run StreamlitApp
$ docker-compose up
# stop StreamlitApp
$ docker-compose down
# run StreamlitApp as daemon
$ docker-compose up -d# run StreamlitApp
$ docker-compose up
# stop StreamlitApp
$ docker-compose down
# run StreamlitApp as daemon
$ docker-compose up -dOthers links:
- Install Streamlit in CentOS7 [en]
- Document architectures using the C4-Model [pt-BR]
- Install Jupyter Notebook no CentOS 7 e python 3.7 [en]
If you liked our tutorials share on your social networks