Spaces:
Running
Running
Update Dockerfile
Browse files- Dockerfile +35 -10
Dockerfile
CHANGED
@@ -1,21 +1,46 @@
|
|
|
|
1 |
FROM python:3.9-slim
|
2 |
|
3 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
WORKDIR /app
|
5 |
|
6 |
-
# Copy the requirements file
|
|
|
7 |
COPY requirements.txt .
|
8 |
|
9 |
-
# Install the
|
10 |
-
|
11 |
-
RUN
|
12 |
-
RUN pip install opencv-python-headless
|
13 |
|
14 |
-
#
|
|
|
|
|
15 |
COPY . .
|
16 |
|
17 |
-
#
|
|
|
18 |
EXPOSE 7860
|
19 |
|
20 |
-
#
|
21 |
-
|
|
|
|
1 |
+
# Start with a slim and secure Python base image
|
2 |
FROM python:3.9-slim
|
3 |
|
4 |
+
# --- Environment Variables ---
|
5 |
+
# Prevents Python from writing .pyc files to disc
|
6 |
+
ENV PYTHONDONTWRITEBYTECODE 1
|
7 |
+
# Ensures Python output is sent straight to the terminal without buffering
|
8 |
+
ENV PYTHONUNBUFFERED 1
|
9 |
+
# Set the MPLCONFIGDIR to a writable directory to avoid matplotlib warnings
|
10 |
+
ENV MPLCONFIGDIR /tmp/matplotlib
|
11 |
+
|
12 |
+
# --- System Dependencies ---
|
13 |
+
# First, update the package lists and install system libraries required by OpenCV.
|
14 |
+
# Combining these into a single RUN layer reduces image size.
|
15 |
+
# libglib2.0-0 is essential to fix the "libgthread-2.0.so.0" error.
|
16 |
+
RUN apt-get update && \
|
17 |
+
apt-get install -y --no-install-recommends \
|
18 |
+
libgl1-mesa-glx \
|
19 |
+
libglib2.0-0 && \
|
20 |
+
# Clean up the apt cache to reduce image size
|
21 |
+
rm -rf /var/lib/apt/lists/*
|
22 |
+
|
23 |
+
# --- Python Dependencies ---
|
24 |
+
# Set the working directory
|
25 |
WORKDIR /app
|
26 |
|
27 |
+
# Copy only the requirements file first to leverage Docker's layer caching.
|
28 |
+
# This layer will only be re-run if requirements.txt changes.
|
29 |
COPY requirements.txt .
|
30 |
|
31 |
+
# Install Python dependencies from the requirements file.
|
32 |
+
# --no-cache-dir reduces image size.
|
33 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
|
|
34 |
|
35 |
+
# --- Application Code ---
|
36 |
+
# Now, copy the rest of the application code into the container.
|
37 |
+
# This layer will be rebuilt on code changes, but the dependencies above will not.
|
38 |
COPY . .
|
39 |
|
40 |
+
# --- Port and Command ---
|
41 |
+
# Expose the port the application will run on
|
42 |
EXPOSE 7860
|
43 |
|
44 |
+
# The command to run the application
|
45 |
+
# Using a list format is the recommended way to write CMD
|
46 |
+
CMD ["uvicorn", "predict:app", "--host", "0.0.0.0", "--port", "7860"]
|