Spaces:
Build error
Build error
Update Dockerfile
Browse files- Dockerfile +43 -18
Dockerfile
CHANGED
@@ -1,38 +1,63 @@
|
|
1 |
-
#
|
2 |
-
FROM python:3.9-slim
|
3 |
|
4 |
# Set the working directory in the container
|
5 |
WORKDIR /app
|
6 |
|
7 |
-
# Install system dependencies
|
8 |
-
# build-essential is
|
9 |
-
#
|
10 |
RUN apt-get update && apt-get install -y \
|
11 |
build-essential \
|
12 |
curl \
|
13 |
-
|
14 |
&& rm -rf /var/lib/apt/lists/*
|
15 |
|
16 |
-
# Copy the requirements file
|
17 |
COPY requirements.txt ./
|
18 |
|
19 |
# Install Python dependencies
|
|
|
20 |
RUN pip3 install --no-cache-dir -r requirements.txt
|
21 |
|
22 |
-
#
|
23 |
-
|
24 |
-
COPY app.py ./
|
25 |
-
COPY css/ ./css/
|
26 |
-
# If your app code is in a 'src' directory:
|
27 |
-
# COPY src/ ./src/
|
28 |
-
# Ensure your app.py is then correctly referenced by the ENTRYPOINT, e.g., "src/app.py"
|
29 |
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
EXPOSE 8501
|
32 |
|
33 |
-
# Healthcheck for Streamlit
|
34 |
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
35 |
|
36 |
-
#
|
37 |
-
# This will run: streamlit run app.py --server.port=8501 --server.address=0.0.0.0
|
38 |
ENTRYPOINT ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]
|
|
|
1 |
+
# Stage 1: Base image with Python
|
2 |
+
FROM python:3.9-slim AS base
|
3 |
|
4 |
# Set the working directory in the container
|
5 |
WORKDIR /app
|
6 |
|
7 |
+
# Install essential system dependencies
|
8 |
+
# build-essential is for compiling Python packages if needed
|
9 |
+
# curl is for the healthcheck
|
10 |
RUN apt-get update && apt-get install -y \
|
11 |
build-essential \
|
12 |
curl \
|
13 |
+
# Add any other specific system dependencies here if errors occur during pip install
|
14 |
&& rm -rf /var/lib/apt/lists/*
|
15 |
|
16 |
+
# Copy the requirements file
|
17 |
COPY requirements.txt ./
|
18 |
|
19 |
# Install Python dependencies
|
20 |
+
# Using --no-cache-dir to keep the image size smaller
|
21 |
RUN pip3 install --no-cache-dir -r requirements.txt
|
22 |
|
23 |
+
# Stage 2: Application image (copies only necessary artifacts from base)
|
24 |
+
FROM python:3.9-slim AS final
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
+
WORKDIR /app
|
27 |
+
|
28 |
+
# Copy Python environment from the base stage (if you had a more complex venv setup, otherwise not strictly needed if pip install is here)
|
29 |
+
# For simplicity with direct pip install, we can skip copying venv from another stage if not explicitly created.
|
30 |
+
# We'll ensure dependencies are installed directly or ensure this stage also has them.
|
31 |
+
# Re-installing system deps or copying from base are options. Let's keep it simple:
|
32 |
+
|
33 |
+
RUN apt-get update && apt-get install -y \
|
34 |
+
curl \
|
35 |
+
# Minimal runtime system dependencies
|
36 |
+
&& rm -rf /var/lib/apt/lists/*
|
37 |
+
|
38 |
+
# Copy installed Python packages from the 'base' stage's site-packages
|
39 |
+
# This path might vary slightly depending on the python:3.9-slim image, find it with `python -m site`
|
40 |
+
# A common path for global site-packages in slim images.
|
41 |
+
# Adjust if your pip install location is different or if you prefer to re-run pip install here.
|
42 |
+
COPY --from=base /usr/local/lib/python3.9/site-packages/ /usr/local/lib/python3.9/site-packages/
|
43 |
+
COPY --from=base /usr/local/bin/ /usr/local/bin/
|
44 |
+
|
45 |
+
# Create necessary directories for your application
|
46 |
+
RUN mkdir -p /app/face_detector /app/css /app/images
|
47 |
+
|
48 |
+
# Copy your application code and model files
|
49 |
+
COPY app.py ./app.py
|
50 |
+
COPY deploy.prototxt /app/face_detector/deploy.prototxt
|
51 |
+
COPY res10_300x300_ssd_iter_140000.caffemodel /app/face_detector/res10_300x300_ssd_iter_140000.caffemodel
|
52 |
+
COPY mask_detector.h5 ./mask_detector.h5
|
53 |
+
COPY styles.css /app/css/styles.css
|
54 |
+
COPY out.jpg /app/images/out.jpg
|
55 |
+
|
56 |
+
# Expose the port Streamlit runs on
|
57 |
EXPOSE 8501
|
58 |
|
59 |
+
# Healthcheck for Streamlit
|
60 |
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
61 |
|
62 |
+
# Set the entrypoint to run the Streamlit application
|
|
|
63 |
ENTRYPOINT ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]
|