Spaces:
Sleeping
Sleeping
Vela
commited on
Commit
·
f12c210
1
Parent(s):
a07193f
Modified dockerfile
Browse files- Dockerfile +33 -2
Dockerfile
CHANGED
|
@@ -1,17 +1,48 @@
|
|
| 1 |
# Use an official Python runtime as the base image
|
|
|
|
| 2 |
FROM python:3.9-slim
|
| 3 |
|
| 4 |
# Set the working directory inside the container
|
|
|
|
| 5 |
WORKDIR /app
|
| 6 |
|
| 7 |
# Copy the local files into the container
|
|
|
|
| 8 |
COPY . /app
|
| 9 |
|
| 10 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 12 |
|
| 13 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
EXPOSE 7860
|
| 15 |
|
| 16 |
# Command to run the application using uvicorn
|
|
|
|
|
|
|
|
|
|
| 17 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 1 |
# Use an official Python runtime as the base image
|
| 2 |
+
# This image contains Python 3.9 and is a lightweight slim version to minimize image size
|
| 3 |
FROM python:3.9-slim
|
| 4 |
|
| 5 |
# Set the working directory inside the container
|
| 6 |
+
# All subsequent commands will run in this /app directory
|
| 7 |
WORKDIR /app
|
| 8 |
|
| 9 |
# Copy the local files into the container
|
| 10 |
+
# Copies everything from the current directory on the host machine to /app in the container
|
| 11 |
COPY . /app
|
| 12 |
|
| 13 |
+
# Set environment variable for Hugging Face cache directory
|
| 14 |
+
# This helps set a custom cache location for Hugging Face models and datasets
|
| 15 |
+
ENV HF_HOME=/app/.cache
|
| 16 |
+
|
| 17 |
+
# Create the necessary cache directories for Hugging Face
|
| 18 |
+
# This ensures that Hugging Face has the required directories set up for caching
|
| 19 |
+
|
| 20 |
+
RUN mkdir -p /app/.cache/huggingface/hub && \
|
| 21 |
+
chmod -R 777 /app/.cache && \
|
| 22 |
+
chmod -R 777 /app/.cache/huggingface
|
| 23 |
+
|
| 24 |
+
# Upgrade pip to the latest version
|
| 25 |
+
# This ensures you are using the most up-to-date version of pip for installing dependencies
|
| 26 |
+
RUN pip install --upgrade pip
|
| 27 |
+
|
| 28 |
+
# Install the dependencies listed in requirements.txt
|
| 29 |
+
# The --no-cache-dir flag ensures pip does not use or store cached versions of packages, saving space
|
| 30 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 31 |
|
| 32 |
+
# Copy the requirements.txt file with ownership changes
|
| 33 |
+
# --chown=user ensures that the requirements.txt file inside the container is owned by a specific user (e.g., user) for security and permissions
|
| 34 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
| 35 |
+
|
| 36 |
+
# Reinstall dependencies from the requirements.txt
|
| 37 |
+
# Installing again to ensure the dependencies are properly set with the correct ownership and permissions
|
| 38 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 39 |
+
|
| 40 |
+
# Expose the port the app will run on
|
| 41 |
+
# FastAPI typically runs on port 8000, but we’re using 7860 in this case
|
| 42 |
EXPOSE 7860
|
| 43 |
|
| 44 |
# Command to run the application using uvicorn
|
| 45 |
+
# Uvicorn is an ASGI server that runs the FastAPI app
|
| 46 |
+
# --host 0.0.0.0 makes the app accessible to any IP address, so it's reachable from outside the container
|
| 47 |
+
# --port 7860 sets the port number on which the FastAPI app will be available
|
| 48 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|