Spaces:
Runtime error
Runtime error
Update Dockerfile
Browse files- Dockerfile +41 -32
Dockerfile
CHANGED
|
@@ -1,32 +1,41 @@
|
|
| 1 |
-
# Use an official lightweight Python image
|
| 2 |
-
FROM python:3.10-slim
|
| 3 |
-
|
| 4 |
-
# Set the working directory inside the container
|
| 5 |
-
WORKDIR /app
|
| 6 |
-
|
| 7 |
-
# Install system dependencies
|
| 8 |
-
# git is needed for some pip packages, build-essential for C extensions
|
| 9 |
-
RUN apt-get update && apt-get install -y \
|
| 10 |
-
build-essential \
|
| 11 |
-
git \
|
| 12 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 13 |
-
|
| 14 |
-
#
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
#
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
#
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
#
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use an official lightweight Python image
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Set the working directory inside the container
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Install system dependencies
|
| 8 |
+
# git is needed for some pip packages, build-essential for C extensions
|
| 9 |
+
RUN apt-get update && apt-get install -y \
|
| 10 |
+
build-essential \
|
| 11 |
+
git \
|
| 12 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 13 |
+
|
| 14 |
+
# --- Additions for Virtual Environment ---
|
| 15 |
+
# 1. Create the virtual environment in a standard location
|
| 16 |
+
RUN python3 -m venv /opt/venv
|
| 17 |
+
|
| 18 |
+
# 2. Add the venv's bin directory to the PATH
|
| 19 |
+
# This effectively "activates" the venv for all subsequent commands
|
| 20 |
+
ENV PATH="/opt/venv/bin:$PATH"
|
| 21 |
+
# --- End of Venv Additions ---
|
| 22 |
+
|
| 23 |
+
# Copy the requirements file first to leverage Docker layer caching
|
| 24 |
+
COPY requirements.txt requirements.txt
|
| 25 |
+
|
| 26 |
+
# Install Python dependencies
|
| 27 |
+
# This pip command will now use the venv's pip
|
| 28 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 29 |
+
|
| 30 |
+
# Copy the rest of your application code into the container
|
| 31 |
+
COPY . .
|
| 32 |
+
|
| 33 |
+
# Expose the port the app will run on
|
| 34 |
+
EXPOSE 7860
|
| 35 |
+
|
| 36 |
+
# Set the port as an environment variable
|
| 37 |
+
ENV PORT=7860
|
| 38 |
+
|
| 39 |
+
# Command to run the application in production using Gunicorn
|
| 40 |
+
# This gunicorn command will use the venv's gunicorn (thanks to the PATH update)
|
| 41 |
+
CMD ["gunicorn", "--workers", "4", "--bind", "0.0.0.0:7860", "main:app"]
|