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:
FROM python:3.7 # Expose port you want your app on EXPOSE 8080 # Upgrade pip and install requirements COPY requirements.txt requirements.txt RUN pip install -U pip RUN pip install -r requirements.txt # Copy app code and set working directory COPY . . WORKDIR /app # Run ENTRYPOINT [“streamlit”, “run”, “Home.py”, “–server.port=8080”, “–server.address=0.0.0.0”]
If you combine this answer with the following docker-compose then you have a nice container containing your app:
services: streamlit: container_name: "The name you want your container to have" build: dockerfile: ./Dockerfile context: ./ ports: - 'The port you want your app to have:8080'
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:
docker compose up -d
if docker compose is not installed please use:
sudo apt-get update sudo apt-get install docker-compose-plugin
In case that you cannot install it so easily use this link