Skip to content

Instantly share code, notes, and snippets.

View collinprather's full-sized avatar

Collin Prather collinprather

View GitHub Profile

Deploying web apps with Streamlit, Docker and AWS

In this tutorial, we will be assuming the following:

  • You have a working Streamlit app ready to deploy
    • If you don't, no worries! The streamlit docs have some great tutorials, but if you'd rather jump right in, you can go ahead and git clone my small example here.
  • You have Docker installed
  • You have a working knowledge of the command line

Streamlit is the framework featured in this post as it is designed for data scientists and machine learning engineers to quickly elevate their analysis from their laptops to deployment. Building useful, aesthetically-pleasing web applications is a diffult thing to do and Streamlit has taken great strides in enabling analysts with little web development experience to "create beautiful data apps in hours, not weeks."

$ docker-compose down
Stopping postgres ... done
Stopping streamlit ... done
Removing postgres ... done
Removing streamlit ... done
Removing network streamlit-docker_default
$ docker exec -it postgres psql -U <username> -d streamlit_db
psql (12.2 (Debian 12.2-2.pgdg100+1))
Type "help" for help.
streamlit_db=# select RM, LSTAT, PRICE
streamlit_db-# from boston
streamlit_db-# where RM > 7
streamlit_db-# limit 2;
rm | lstat | price
-------+-------+-------
$ docker logs -f postgres
.
.
. <various log messages>
.
.
2020-03-12 13:13:56.831 UTC [1] LOG: database system is ready to accept connections
$ docker-compose up -d
Creating network "streamlit-docker_default" with the default driver
Creating streamlit ... done
Creating postgres ... done
CMD python3 scripts/load_docker_db.py
streamlit:
build:
context: .
container_name: "streamlit"
ports:
- "8501:8501"
volumes:
db_data:
db:
image: "postgres:12"
container_name: "postgres"
ports:
- "5432:5432"
volumes:
- db_data:/var/lib/postgresql/data
env_file:
- .env
version: "3.7"