Update Dockerfile
Browse files- Dockerfile +7 -12
Dockerfile
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
# 1. Use
|
| 2 |
FROM python:3.12-slim
|
| 3 |
|
| 4 |
# 2. Set environment variables
|
|
@@ -6,36 +6,31 @@ ENV PYTHONUNBUFFERED=1 \
|
|
| 6 |
PYTHONDONTWRITEBYTECODE=1 \
|
| 7 |
PORT=7860
|
| 8 |
|
| 9 |
-
# 3. Set the working directory in the container
|
| 10 |
WORKDIR /app
|
| 11 |
|
| 12 |
-
#
|
|
|
|
| 13 |
RUN apt-get update && apt-get install -y \
|
| 14 |
build-essential \
|
| 15 |
curl \
|
| 16 |
-
software-properties-common \
|
| 17 |
&& rm -rf /var/lib/apt/lists/*
|
| 18 |
|
| 19 |
-
#
|
| 20 |
COPY requirements.txt .
|
| 21 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 22 |
|
| 23 |
-
#
|
| 24 |
COPY . .
|
| 25 |
|
| 26 |
-
#
|
| 27 |
RUN useradd -m -u 1000 user
|
| 28 |
USER user
|
| 29 |
ENV HOME=/home/user \
|
| 30 |
PATH=/home/user/.local/bin:$PATH
|
| 31 |
-
|
| 32 |
-
# 8. Set the working directory to where the code lives
|
| 33 |
WORKDIR $HOME/app
|
| 34 |
COPY --chown=user . $HOME/app
|
| 35 |
|
| 36 |
-
# 9. Expose the port Hugging Face Spaces expects
|
| 37 |
EXPOSE 7860
|
| 38 |
|
| 39 |
-
#
|
| 40 |
-
# Replace 'app.main:app' with your actual FastAPI entry point
|
| 41 |
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 1 |
+
# 1. Use the official Python slim image
|
| 2 |
FROM python:3.12-slim
|
| 3 |
|
| 4 |
# 2. Set environment variables
|
|
|
|
| 6 |
PYTHONDONTWRITEBYTECODE=1 \
|
| 7 |
PORT=7860
|
| 8 |
|
|
|
|
| 9 |
WORKDIR /app
|
| 10 |
|
| 11 |
+
# 3. Install ONLY necessary system dependencies
|
| 12 |
+
# Removed 'software-properties-common' as it is obsolete in Debian Trixie
|
| 13 |
RUN apt-get update && apt-get install -y \
|
| 14 |
build-essential \
|
| 15 |
curl \
|
|
|
|
| 16 |
&& rm -rf /var/lib/apt/lists/*
|
| 17 |
|
| 18 |
+
# 4. Install Python dependencies
|
| 19 |
COPY requirements.txt .
|
| 20 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 21 |
|
| 22 |
+
# 5. Copy application code
|
| 23 |
COPY . .
|
| 24 |
|
| 25 |
+
# 6. Hugging Face security best practices
|
| 26 |
RUN useradd -m -u 1000 user
|
| 27 |
USER user
|
| 28 |
ENV HOME=/home/user \
|
| 29 |
PATH=/home/user/.local/bin:$PATH
|
|
|
|
|
|
|
| 30 |
WORKDIR $HOME/app
|
| 31 |
COPY --chown=user . $HOME/app
|
| 32 |
|
|
|
|
| 33 |
EXPOSE 7860
|
| 34 |
|
| 35 |
+
# 7. Run the application
|
|
|
|
| 36 |
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
|