Tutorials / pages /3_300_Run_streamlit_in_Docker.py
MrJShen's picture
Upload 3_300_Run_streamlit_in_Docker.py
ad0267c
import streamlit as st
from utils import *
st.markdown("# Steps to run streamlit with Docker")
st.image("https://jenkov.com/images/docker/docker-introduction-2.png", width=600,)
st.markdown(
"""
#### :blue[For MacOS:]
###### 1. Download Docker Desktop
- Check the webside [here](https://docs.docker.com/desktop/install/mac-install/) to download
###### 2. Check version
```bash
sudo docker --version
```
###### 3. Add Docker to path
```bash
export PATH=$PATH:/usr/local/bin/docker
```
###### 4. Create Dockerfile
- go to your app directory, touch a file named Dockerfile, then copy the following code and save
```cmd
FROM harpershen/aiclububuntu
RUN apt update
RUN apt install --assume-yes python3-pip
WORKDIR /usr/app
COPY . .
RUN pip install -r requirements.txt
CMD [ "streamlit", "run", "app.py"]
```
###### 5. create requirements.txt
- at the same app directory, touch a file requirements.txt, then copy the following and save:
```cmd
pandas
streamlit
numpy
matplotlib
plotly
nltk
python-dotenv
openai
extra_streamlit_components
streamlit_book
spacy_streamlit
```
###### 6. Build docker image
- in the Terminal, at the app directory, typing and run:
```cmd
docker build -t streamlit-runner .
```
###### 7. Run docker container
- in the Terminal, at the app directory, typing and run:
```cmd
docker run -d -p 8501:8501 -v .:/usr/app streamlit-runner
```
###### 8. Further reading on remove/clean image and containers
- Check the webside [here](https://www.digitalocean.com/community/tutorials/how-to-remove-docker-images-containers-and-volumes/) to learn
"""
)