Spaces:
Building
Building
Update Dockerfile
Browse files- Dockerfile +31 -15
Dockerfile
CHANGED
@@ -2,14 +2,16 @@
|
|
2 |
|
3 |
FROM python:3.8
|
4 |
|
5 |
-
# Create a non-root user
|
6 |
RUN useradd -m -u 1000 user
|
|
|
|
|
7 |
USER user
|
8 |
WORKDIR /home/user
|
9 |
|
10 |
ENV PATH="/home/user/.local/bin:$PATH"
|
11 |
|
12 |
-
# Install system packages
|
13 |
USER root
|
14 |
RUN apt-get update && \
|
15 |
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
|
@@ -23,10 +25,13 @@ RUN apt-get update && \
|
|
23 |
build-essential \
|
24 |
libgl1-mesa-glx \
|
25 |
libglib2.0-0 \
|
|
|
26 |
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
|
27 |
USER user
|
28 |
|
29 |
-
# Install Python dependencies
|
30 |
RUN pip install --no-cache-dir --upgrade pip setuptools wheel
|
31 |
RUN pip install --no-cache-dir openmim
|
32 |
RUN pip install --no-cache-dir torch==2.0.0
|
@@ -34,37 +39,48 @@ RUN mim install mmcv-full==1.7.0
|
|
34 |
RUN pip install --no-cache-dir mmdet==2.27.0
|
35 |
RUN pip install --no-cache-dir torchserve
|
36 |
|
37 |
-
# Clone and install xtcocoapi (a dependency for mmpose)
|
38 |
RUN git clone https://github.com/jin-s13/xtcocoapi.git
|
39 |
WORKDIR xtcocoapi
|
40 |
RUN pip install --no-cache-dir -r requirements.txt
|
41 |
RUN pip install -e .
|
42 |
WORKDIR /home/user
|
43 |
|
44 |
-
# Install additional Python packages
|
45 |
RUN pip install --no-cache-dir mmpose==0.29.0
|
46 |
RUN pip install --no-cache-dir torchvision==0.15.1 numpy==1.24.4
|
47 |
|
48 |
-
# Copy your application code
|
49 |
COPY --chown=user . .
|
50 |
|
51 |
-
# Install your application's Python dependencies
|
52 |
RUN pip install --no-cache-dir -e .
|
53 |
|
54 |
-
# Prepare TorchServe model-store and download necessary models
|
55 |
RUN mkdir -p /home/user/torchserve/model-store
|
56 |
RUN wget https://github.com/facebookresearch/AnimatedDrawings/releases/download/v0.0.1/drawn_humanoid_detector.mar -P /home/user/torchserve/model-store/
|
57 |
RUN wget https://github.com/facebookresearch/AnimatedDrawings/releases/download/v0.0.1/drawn_humanoid_pose_estimator.mar -P /home/user/torchserve/model-store/
|
58 |
|
59 |
-
#
|
60 |
-
|
|
|
|
|
|
|
|
|
61 |
|
62 |
-
# Copy the start.sh script
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
-
# Expose necessary ports
|
67 |
EXPOSE 7860 8080 8081 8082
|
68 |
|
69 |
-
#
|
70 |
CMD ["/home/user/start.sh"]
|
|
|
2 |
|
3 |
FROM python:3.8
|
4 |
|
5 |
+
# 1. Create a non-root user
|
6 |
RUN useradd -m -u 1000 user
|
7 |
+
|
8 |
+
# 2. Switch to the non-root user
|
9 |
USER user
|
10 |
WORKDIR /home/user
|
11 |
|
12 |
ENV PATH="/home/user/.local/bin:$PATH"
|
13 |
|
14 |
+
# 3. Install system packages as root
|
15 |
USER root
|
16 |
RUN apt-get update && \
|
17 |
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
|
|
|
25 |
build-essential \
|
26 |
libgl1-mesa-glx \
|
27 |
libglib2.0-0 \
|
28 |
+
netcat \
|
29 |
&& rm -rf /var/lib/apt/lists/*
|
30 |
+
|
31 |
+
# 4. Switch back to the non-root user
|
32 |
USER user
|
33 |
|
34 |
+
# 5. Install Python dependencies
|
35 |
RUN pip install --no-cache-dir --upgrade pip setuptools wheel
|
36 |
RUN pip install --no-cache-dir openmim
|
37 |
RUN pip install --no-cache-dir torch==2.0.0
|
|
|
39 |
RUN pip install --no-cache-dir mmdet==2.27.0
|
40 |
RUN pip install --no-cache-dir torchserve
|
41 |
|
42 |
+
# 6. Clone and install xtcocoapi (a dependency for mmpose)
|
43 |
RUN git clone https://github.com/jin-s13/xtcocoapi.git
|
44 |
WORKDIR xtcocoapi
|
45 |
RUN pip install --no-cache-dir -r requirements.txt
|
46 |
RUN pip install -e .
|
47 |
WORKDIR /home/user
|
48 |
|
49 |
+
# 7. Install additional Python packages
|
50 |
RUN pip install --no-cache-dir mmpose==0.29.0
|
51 |
RUN pip install --no-cache-dir torchvision==0.15.1 numpy==1.24.4
|
52 |
|
53 |
+
# 8. Copy your application code with appropriate ownership
|
54 |
COPY --chown=user . .
|
55 |
|
56 |
+
# 9. Install your application's Python dependencies
|
57 |
RUN pip install --no-cache-dir -e .
|
58 |
|
59 |
+
# 10. Prepare TorchServe model-store and download necessary models
|
60 |
RUN mkdir -p /home/user/torchserve/model-store
|
61 |
RUN wget https://github.com/facebookresearch/AnimatedDrawings/releases/download/v0.0.1/drawn_humanoid_detector.mar -P /home/user/torchserve/model-store/
|
62 |
RUN wget https://github.com/facebookresearch/AnimatedDrawings/releases/download/v0.0.1/drawn_humanoid_pose_estimator.mar -P /home/user/torchserve/model-store/
|
63 |
|
64 |
+
# 11. Switch to root to copy configuration files and set permissions
|
65 |
+
USER root
|
66 |
+
|
67 |
+
# 12. Copy TorchServe configuration files
|
68 |
+
COPY config.properties /home/user/torchserve/config.properties
|
69 |
+
COPY config.local.properties /home/user/torchserve/config.local.properties
|
70 |
|
71 |
+
# 13. Copy the start.sh script and set executable permissions
|
72 |
+
# Option A: Using --chmod flag (Recommended)
|
73 |
+
COPY --chmod=0755 start.sh /home/user/start.sh
|
74 |
+
|
75 |
+
# Option B: Without using --chmod flag (if Docker version < 17.09)
|
76 |
+
# COPY start.sh /home/user/start.sh
|
77 |
+
# RUN chmod +x /home/user/start.sh
|
78 |
+
|
79 |
+
# 14. Switch back to the non-root user
|
80 |
+
USER user
|
81 |
|
82 |
+
# 15. Expose necessary ports
|
83 |
EXPOSE 7860 8080 8081 8082
|
84 |
|
85 |
+
# 16. Define the entrypoint command to start both TorchServe and Gradio
|
86 |
CMD ["/home/user/start.sh"]
|