Update Dockerfile
Browse files- Dockerfile +27 -12
Dockerfile
CHANGED
@@ -1,39 +1,54 @@
|
|
1 |
-
# Dockerfile for Streamlit app in
|
2 |
|
3 |
# 1. Base image
|
4 |
FROM python:3.9-slim
|
5 |
|
6 |
-
# 2.
|
|
|
|
|
|
|
7 |
WORKDIR /app
|
8 |
|
9 |
-
#
|
10 |
ENV HOME=/app
|
11 |
|
12 |
-
#
|
13 |
ENV STREAMLIT_CONFIG_DIR=/app/.streamlit \
|
14 |
TRANSFORMERS_CACHE=/app/.cache/huggingface/hub \
|
15 |
HF_HOME=/app/.cache/huggingface \
|
16 |
XDG_CACHE_HOME=/app/.cache \
|
17 |
STREAMLIT_HOME=/app/.cache/streamlit
|
18 |
|
19 |
-
#
|
20 |
RUN mkdir -p /app/.streamlit \
|
21 |
&& mkdir -p /app/.cache/huggingface/hub \
|
22 |
&& mkdir -p /app/.cache/streamlit \
|
23 |
-
&& chmod -R
|
24 |
-
&&
|
|
|
|
|
|
|
25 |
|
26 |
-
#
|
27 |
COPY requirements.txt .
|
28 |
RUN pip install --no-cache-dir -r requirements.txt
|
29 |
|
30 |
-
#
|
31 |
COPY src/ ./src
|
32 |
|
33 |
-
#
|
|
|
|
|
|
|
|
|
|
|
34 |
EXPOSE 8501
|
35 |
|
36 |
-
#
|
|
|
|
|
|
|
|
|
37 |
CMD ["streamlit", "run", "src/app.py", \
|
38 |
"--server.port=8501", \
|
39 |
-
"--server.address=0.0.0.0"]
|
|
|
1 |
+
# Dockerfile for Streamlit app in src/ folder with Transformers cache fix
|
2 |
|
3 |
# 1. Base image
|
4 |
FROM python:3.9-slim
|
5 |
|
6 |
+
# 2. Create non-root user for security
|
7 |
+
RUN useradd -m -u 1000 appuser
|
8 |
+
|
9 |
+
# 3. Set working directory
|
10 |
WORKDIR /app
|
11 |
|
12 |
+
# 4. Set HOME to /app to avoid writing to root
|
13 |
ENV HOME=/app
|
14 |
|
15 |
+
# 5. Environment variables for writable cache/config dirs
|
16 |
ENV STREAMLIT_CONFIG_DIR=/app/.streamlit \
|
17 |
TRANSFORMERS_CACHE=/app/.cache/huggingface/hub \
|
18 |
HF_HOME=/app/.cache/huggingface \
|
19 |
XDG_CACHE_HOME=/app/.cache \
|
20 |
STREAMLIT_HOME=/app/.cache/streamlit
|
21 |
|
22 |
+
# 6. Create cache directories with correct permissions
|
23 |
RUN mkdir -p /app/.streamlit \
|
24 |
&& mkdir -p /app/.cache/huggingface/hub \
|
25 |
&& mkdir -p /app/.cache/streamlit \
|
26 |
+
&& chmod -R 755 /app/.cache /app/.streamlit \
|
27 |
+
&& chown -R appuser:appuser /app
|
28 |
+
|
29 |
+
# 7. Switch to non-root user
|
30 |
+
USER appuser
|
31 |
|
32 |
+
# 8. Copy in dependency file and install
|
33 |
COPY requirements.txt .
|
34 |
RUN pip install --no-cache-dir -r requirements.txt
|
35 |
|
36 |
+
# 9. Copy your source app code and Streamlit config
|
37 |
COPY src/ ./src
|
38 |
|
39 |
+
# 10. Move .streamlit/config.toml to the correct location
|
40 |
+
RUN if [ -f /app/src/.streamlit/config.toml ]; then \
|
41 |
+
mv /app/src/.streamlit/config.toml /app/.streamlit/config.toml; \
|
42 |
+
fi
|
43 |
+
|
44 |
+
# 11. Expose Streamlit default port
|
45 |
EXPOSE 8501
|
46 |
|
47 |
+
# 12. Healthcheck to verify app is running
|
48 |
+
HEALTHCHECK --interval=30s --timeout=3s \
|
49 |
+
CMD curl -f http://localhost:8501/healthz || exit 1
|
50 |
+
|
51 |
+
# 13. Launch Streamlit pointing to src/app.py
|
52 |
CMD ["streamlit", "run", "src/app.py", \
|
53 |
"--server.port=8501", \
|
54 |
+
"--server.address=0.0.0.0"]
|