Update Dockerfile
Browse files- Dockerfile +20 -13
Dockerfile
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
FROM python:3.10-slim
|
| 2 |
|
| 3 |
-
# Install system dependencies
|
|
|
|
|
|
|
| 4 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 5 |
build-essential \
|
| 6 |
wget \
|
|
@@ -9,7 +11,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
| 9 |
libglib2.0-0 \
|
| 10 |
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
|
| 12 |
-
# Set up
|
| 13 |
RUN useradd -m -u 1000 user
|
| 14 |
USER user
|
| 15 |
ENV HOME=/home/user \
|
|
@@ -17,21 +19,26 @@ ENV HOME=/home/user \
|
|
| 17 |
|
| 18 |
WORKDIR $HOME/app
|
| 19 |
|
| 20 |
-
# Copy requirements
|
| 21 |
COPY --chown=user requirements.txt .
|
| 22 |
|
| 23 |
-
#
|
| 24 |
-
|
| 25 |
-
RUN pip install --no-cache-dir detectron2 \
|
| 26 |
-
--extra-index-url https://wheels.myhloli.com \
|
| 27 |
-
--trusted-host wheels.myhloli.com
|
| 28 |
|
| 29 |
-
#
|
| 30 |
-
|
| 31 |
-
|
|
|
|
| 32 |
|
| 33 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
COPY --chown=user . .
|
| 35 |
|
| 36 |
-
# Run the application
|
| 37 |
CMD ["python", "app.py"]
|
|
|
|
| 1 |
FROM python:3.10-slim
|
| 2 |
|
| 3 |
+
# 1. Install system dependencies required for compiling
|
| 4 |
+
# 'git' is needed to download detectron2 source
|
| 5 |
+
# 'build-essential' provides the compilers (gcc/g++)
|
| 6 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 7 |
build-essential \
|
| 8 |
wget \
|
|
|
|
| 11 |
libglib2.0-0 \
|
| 12 |
&& rm -rf /var/lib/apt/lists/*
|
| 13 |
|
| 14 |
+
# 2. Set up the user
|
| 15 |
RUN useradd -m -u 1000 user
|
| 16 |
USER user
|
| 17 |
ENV HOME=/home/user \
|
|
|
|
| 19 |
|
| 20 |
WORKDIR $HOME/app
|
| 21 |
|
| 22 |
+
# 3. Copy requirements
|
| 23 |
COPY --chown=user requirements.txt .
|
| 24 |
|
| 25 |
+
# 4. Upgrade pip
|
| 26 |
+
RUN pip install --no-cache-dir --upgrade pip
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
# 5. Install PyTorch (CPU Version) FIRST
|
| 29 |
+
# We explicitly install the CPU version to keep the image small and compatible.
|
| 30 |
+
# Detectron2 requires PyTorch to be installed before it can build.
|
| 31 |
+
RUN pip install --no-cache-dir torch torchvision --index-url https://download.pytorch.org/whl/cpu
|
| 32 |
|
| 33 |
+
# 6. Install Detectron2 from Source (Official Facebook Repo)
|
| 34 |
+
# Since we installed 'build-essential' and 'torch', this will compile successfully.
|
| 35 |
+
RUN pip install --no-cache-dir "git+https://github.com/facebookresearch/detectron2.git"
|
| 36 |
+
|
| 37 |
+
# 7. Install the rest of the dependencies
|
| 38 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 39 |
+
|
| 40 |
+
# 8. Copy the application
|
| 41 |
COPY --chown=user . .
|
| 42 |
|
| 43 |
+
# 9. Run the application
|
| 44 |
CMD ["python", "app.py"]
|