Nodiw52992 commited on
Commit
f1b0640
·
verified ·
1 Parent(s): 30e4133

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +15 -4
Dockerfile CHANGED
@@ -2,32 +2,43 @@
2
  FROM ubuntu:24.04
3
  ENV DEBIAN_FRONTEND=noninteractive
4
 
 
5
  RUN apt-get update && apt-get install -y \
6
  python3 python3-venv python3-pip git wget \
7
  && rm -rf /var/lib/apt/lists/*
8
 
 
 
 
9
  WORKDIR /workspace
10
  RUN git clone https://github.com/comfyanonymous/ComfyUI.git
11
  WORKDIR /workspace/ComfyUI
12
 
 
13
  RUN python3 -m venv .venv \
14
  && . .venv/bin/activate \
15
  && pip install --upgrade pip \
16
  && pip install huggingface_hub xformers!=0.0.18 \
17
  && pip install -r requirements.txt
18
 
19
- # Create the user directory with permissive rights
20
- RUN mkdir -p /workspace/ComfyUI/user && chmod -R 777 /workspace/ComfyUI/user
 
21
 
22
  # Copy download script
23
  COPY download_flux.py /workspace/ComfyUI/download_flux.py
24
 
25
- # Use secret to download model files via huggingface_hub
26
  RUN --mount=type=secret,id=HF_TOKEN,mode=0444,required=true \
27
  . .venv/bin/activate && \
28
  python download_flux.py
29
 
 
 
 
 
 
 
30
  EXPOSE 7860
31
 
32
- # Use split cross attention flag and listen on all interfaces, enforce CPU mode
33
  CMD ["/bin/bash", "-c", "source .venv/bin/activate && python3 main.py --listen 0.0.0.0 --port 7860 --cpu --use-split-cross-attention"]
 
2
  FROM ubuntu:24.04
3
  ENV DEBIAN_FRONTEND=noninteractive
4
 
5
+ # Install system deps
6
  RUN apt-get update && apt-get install -y \
7
  python3 python3-venv python3-pip git wget \
8
  && rm -rf /var/lib/apt/lists/*
9
 
10
+ # Create a non-root user
11
+ RUN useradd -m -s /bin/bash comfy
12
+
13
  WORKDIR /workspace
14
  RUN git clone https://github.com/comfyanonymous/ComfyUI.git
15
  WORKDIR /workspace/ComfyUI
16
 
17
+ # Create Python venv & install dependencies as root
18
  RUN python3 -m venv .venv \
19
  && . .venv/bin/activate \
20
  && pip install --upgrade pip \
21
  && pip install huggingface_hub xformers!=0.0.18 \
22
  && pip install -r requirements.txt
23
 
24
+ # Pre-create writable folders
25
+ RUN mkdir -p /workspace/ComfyUI/user /workspace/ComfyUI/temp \
26
+ && chown -R comfy:comfy /workspace/ComfyUI/user /workspace/ComfyUI/temp
27
 
28
  # Copy download script
29
  COPY download_flux.py /workspace/ComfyUI/download_flux.py
30
 
31
+ # Run model download with secret token as root
32
  RUN --mount=type=secret,id=HF_TOKEN,mode=0444,required=true \
33
  . .venv/bin/activate && \
34
  python download_flux.py
35
 
36
+ # Make sure entire repo is owned by comfy (safe for venv)
37
+ RUN chown -R comfy:comfy /workspace/ComfyUI
38
+
39
+ # Switch to comfy user
40
+ USER comfy
41
+
42
  EXPOSE 7860
43
 
 
44
  CMD ["/bin/bash", "-c", "source .venv/bin/activate && python3 main.py --listen 0.0.0.0 --port 7860 --cpu --use-split-cross-attention"]