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”]
This is a series of instructions and each instruction creates a layer. The base image here is python:3.9 where you create a directory called /app, then copy and install everything in your requirements.txt. Then copy your entire folder over and finally specify the command to run within the container. When you run the container it will be exposed on port 8201.
Build and run the container with the following if you are going for a local set up. Run the commands from within the directory your Dockerfile is.
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.
3
Answers
Try something like this.
This is a docker file that would work for you:
This is a series of instructions and each instruction creates a layer. The base image here is
python:3.9
where you create a directory called/app
, then copy and install everything in yourrequirements.txt
. Then copy your entire folder over and finally specify the command to run within the container. When you run the container it will be exposed on port8201
.Build and run the container with the following if you are going for a local set up. Run the commands from within the directory your
Dockerfile
is.Now you will be able to access the container on your browser at
http://localhost:8201/
In order to Dockerise your app you need two files:
Dockerfile
)The answer of Javier Roger is providing a very minimal Dockerfile that seems to work:
If you combine this answer with the following docker-compose then you have a nice container containing your app:
Please note that both
Dockerfile
anddocker-compose.yml
should be placed in the root of your app.To run the app just
cd
to the root dir and run:if docker compose is not installed please use:
In case that you cannot install it so easily use this link