I am aiming to deploy a web-app written with Sreamlit,
I can run this on my local machine by running streamlit run Home.py
in my command line.
However, I’m not sure how to create the docker file.
Any advice?
Advertisement
Answer
In order to Dockerise your app you need two files:
- Dockerfile : describes the image structure,
- docker-compose.yml : describes how to make a container from that image (
Dockerfile
)
The answer of Javier Roger is providing a very minimal Dockerfile that seems to work:
JavaScript
x
17
17
1
FROM python:3.7
2
3
# Expose port you want your app on
4
EXPOSE 8080
5
6
# Upgrade pip and install requirements
7
COPY requirements.txt requirements.txt
8
RUN pip install -U pip
9
RUN pip install -r requirements.txt
10
11
# Copy app code and set working directory
12
COPY . .
13
WORKDIR /app
14
15
# Run
16
ENTRYPOINT [“streamlit”, “run”, “Home.py”, “–server.port=8080”, “–server.address=0.0.0.0”]
17
If you combine this answer with the following docker-compose then you have a nice container containing your app:
JavaScript
1
9
1
services:
2
streamlit:
3
container_name: "The name you want your container to have"
4
build:
5
dockerfile: ./Dockerfile
6
context: ./
7
ports:
8
- 'The port you want your app to have:8080'
9
Please note that both Dockerfile
and docker-compose.yml
should be placed in the root of your app.
To run the app just cd
to the root dir and run:
JavaScript
1
2
1
docker compose up -d
2
if docker compose is not installed please use:
JavaScript
1
3
1
sudo apt-get update
2
sudo apt-get install docker-compose-plugin
3
In case that you cannot install it so easily use this link