Update Dockerfile
Browse files- Dockerfile +58 -42
Dockerfile
CHANGED
|
@@ -1,42 +1,58 @@
|
|
| 1 |
-
# Use the official Python image from the Docker Hub
|
| 2 |
-
FROM python:3.10-slim
|
| 3 |
-
|
| 4 |
-
# Set up a new user named "user" with user ID 1000
|
| 5 |
-
RUN useradd -m -u 1000 user
|
| 6 |
-
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
ENV
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
#
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
#
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
#
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use the official Python image from the Docker Hub
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Set up a new user named "user" with user ID 1000
|
| 5 |
+
RUN useradd -m -u 1000 user
|
| 6 |
+
|
| 7 |
+
# Install system dependencies
|
| 8 |
+
RUN apt-get update && apt-get install -y \
|
| 9 |
+
build-essential \
|
| 10 |
+
curl \
|
| 11 |
+
software-properties-common \
|
| 12 |
+
git \
|
| 13 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 14 |
+
|
| 15 |
+
# Set environment variables for the cache directory (use a writable directory)
|
| 16 |
+
ENV TRANSFORMERS_CACHE=/home/user/.cache/huggingface
|
| 17 |
+
ENV STREAMLIT_SERVER_PORT=7860
|
| 18 |
+
ENV STREAMLIT_SERVER_ADDRESS=0.0.0.0
|
| 19 |
+
|
| 20 |
+
# Create and set the cache directory so the user can write to it
|
| 21 |
+
RUN mkdir -p /home/user/.cache/huggingface && chown -R user:user /home/user/.cache
|
| 22 |
+
|
| 23 |
+
# Switch to the "user" user
|
| 24 |
+
USER user
|
| 25 |
+
|
| 26 |
+
# Set home to the user's home directory
|
| 27 |
+
ENV HOME=/home/user \
|
| 28 |
+
PATH=/home/user/.local/bin:$PATH
|
| 29 |
+
|
| 30 |
+
# Set the working directory to the user's home directory
|
| 31 |
+
WORKDIR $HOME/app
|
| 32 |
+
|
| 33 |
+
# Upgrade pip to the latest version to avoid issues with outdated pip
|
| 34 |
+
RUN pip install --no-cache-dir --upgrade pip
|
| 35 |
+
|
| 36 |
+
# Copy the current directory contents into the container at $HOME/app setting the owner to the user
|
| 37 |
+
COPY --chown=user . $HOME/app
|
| 38 |
+
|
| 39 |
+
# Install dependencies
|
| 40 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 41 |
+
|
| 42 |
+
# Download any necessary assets
|
| 43 |
+
RUN mkdir -p content
|
| 44 |
+
ADD --chown=user https://huggingface.co/datasets/manhteky123/LawVietnamese/resolve/main/data.csv content/data.csv
|
| 45 |
+
ADD --chown=user https://huggingface.co/datasets/manhteky123/LawVietnamese/resolve/main/faiss_index.bin content/faiss_index.bin
|
| 46 |
+
ADD --chown=user https://huggingface.co/datasets/manhteky123/LawVietnamese/resolve/main/vectors.npy content/vectors.npy
|
| 47 |
+
|
| 48 |
+
# Create .streamlit directory and config
|
| 49 |
+
RUN mkdir -p .streamlit
|
| 50 |
+
|
| 51 |
+
# Health check for Streamlit
|
| 52 |
+
HEALTHCHECK CMD curl --fail http://localhost:7860/_stcore/health || exit 1
|
| 53 |
+
|
| 54 |
+
# Expose the port the app runs on (change from 5000 to 7860 for Streamlit)
|
| 55 |
+
EXPOSE 7860
|
| 56 |
+
|
| 57 |
+
# Define the command to run the Streamlit application
|
| 58 |
+
CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0", "--server.headless=true", "--server.enableCORS=false", "--server.enableXsrfProtection=false"]
|