Fix Dockerfile: add curl for HEALTHCHECK and configure UID 1000 permissions
Browse files- Dockerfile +20 -12
Dockerfile
CHANGED
|
@@ -1,12 +1,15 @@
|
|
| 1 |
FROM python:3.11-slim
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
# System deps
|
| 6 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 7 |
-
build-essential git && \
|
| 8 |
rm -rf /var/lib/apt/lists/*
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
# Step 1: Install torch CPU
|
| 11 |
RUN pip install --no-cache-dir torch==2.6.0
|
| 12 |
|
|
@@ -17,18 +20,23 @@ RUN pip install --no-cache-dir torch_scatter torch_sparse -f https://data.pyg.or
|
|
| 17 |
COPY requirements.txt .
|
| 18 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 19 |
|
| 20 |
-
# Copy app code
|
| 21 |
-
COPY . .
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
#
|
| 24 |
-
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
|
| 28 |
-
printf '[server]\nheadless = true\nport = 7860\nenableCORS = false\nenableXsrfProtection = false\n' > /root/.streamlit/config.toml
|
| 29 |
|
| 30 |
EXPOSE 7860
|
| 31 |
|
| 32 |
-
HEALTHCHECK CMD curl --fail http://localhost:7860/_stcore/health
|
| 33 |
|
| 34 |
ENTRYPOINT ["streamlit", "run", "app/main.py", "--server.port=7860", "--server.address=0.0.0.0"]
|
|
|
|
| 1 |
FROM python:3.11-slim
|
| 2 |
|
| 3 |
+
# System deps (added curl for HEALTHCHECK)
|
|
|
|
|
|
|
| 4 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 5 |
+
build-essential git curl && \
|
| 6 |
rm -rf /var/lib/apt/lists/*
|
| 7 |
|
| 8 |
+
# Add a non-root user (Hugging Face Spaces runs as 1000)
|
| 9 |
+
RUN useradd -m -u 1000 appuser
|
| 10 |
+
|
| 11 |
+
WORKDIR /app
|
| 12 |
+
|
| 13 |
# Step 1: Install torch CPU
|
| 14 |
RUN pip install --no-cache-dir torch==2.6.0
|
| 15 |
|
|
|
|
| 20 |
COPY requirements.txt .
|
| 21 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 22 |
|
| 23 |
+
# Copy app code and set ownership
|
| 24 |
+
COPY --chown=appuser:appuser . .
|
| 25 |
+
|
| 26 |
+
# Set environment variables
|
| 27 |
+
ENV PYTHONPATH=/app:$PYTHONPATH \
|
| 28 |
+
HOME=/home/appuser
|
| 29 |
|
| 30 |
+
# Streamlit config (placed in the correct HOME directory)
|
| 31 |
+
RUN mkdir -p /home/appuser/.streamlit && \
|
| 32 |
+
printf '[server]\nheadless = true\nport = 7860\nenableCORS = false\nenableXsrfProtection = false\n' > /home/appuser/.streamlit/config.toml && \
|
| 33 |
+
chown -R appuser:appuser /home/appuser/.streamlit /app
|
| 34 |
|
| 35 |
+
# Switch to the non-root user
|
| 36 |
+
USER appuser
|
|
|
|
| 37 |
|
| 38 |
EXPOSE 7860
|
| 39 |
|
| 40 |
+
HEALTHCHECK CMD curl --fail http://localhost:7860/_stcore/health || exit 1
|
| 41 |
|
| 42 |
ENTRYPOINT ["streamlit", "run", "app/main.py", "--server.port=7860", "--server.address=0.0.0.0"]
|