jimmy60504 commited on
Commit
f237f2d
·
1 Parent(s): f34140c

update Dockerfile and image_python.sh for non-root user support and improved volume mounting

Browse files
Files changed (2) hide show
  1. Dockerfile +17 -4
  2. image_python.sh +7 -8
Dockerfile CHANGED
@@ -5,9 +5,13 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
5
  PYTHONUNBUFFERED=1 \
6
  PIP_NO_CACHE_DIR=1 \
7
  GRADIO_SERVER_PORT=7860 \
8
- GRADIO_SERVER_NAME=0.0.0.0
 
9
 
10
- # 基本系統套件與科學計算依賴(netCDF4/scipy)
 
 
 
11
  RUN apt-get update && apt-get install -y --no-install-recommends \
12
  build-essential \
13
  libhdf5-dev \
@@ -17,8 +21,17 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
17
  git \
18
  && rm -rf /var/lib/apt/lists/*
19
 
20
- COPY requirements.txt /tmp/
21
- RUN pip install --upgrade pip && pip install -r /tmp/requirements.txt
 
 
 
 
 
 
 
22
 
23
  EXPOSE 7860
24
 
 
 
 
5
  PYTHONUNBUFFERED=1 \
6
  PIP_NO_CACHE_DIR=1 \
7
  GRADIO_SERVER_PORT=7860 \
8
+ GRADIO_SERVER_NAME=0.0.0.0 \
9
+ HOME=/home/user
10
 
11
+ # 建立非 root 使用者(與 HF Spaces 一致)
12
+ RUN useradd -m -u 1000 user
13
+
14
+ # 基本系統套件與科學計算依賴
15
  RUN apt-get update && apt-get install -y --no-install-recommends \
16
  build-essential \
17
  libhdf5-dev \
 
21
  git \
22
  && rm -rf /var/lib/apt/lists/*
23
 
24
+ # 切換到使用者目錄
25
+ WORKDIR $HOME/app
26
+
27
+ # 只複製 requirements.txt 並安裝
28
+ COPY --chown=user:user requirements.txt .
29
+ RUN pip install --upgrade pip && pip install -r requirements.txt
30
+
31
+ # 切換到非 root 使用者
32
+ USER user
33
 
34
  EXPOSE 7860
35
 
36
+ # 預設執行命令(可被 docker run 覆蓋)
37
+ CMD ["python", "app.py"]
image_python.sh CHANGED
@@ -1,10 +1,9 @@
 
1
  docker container rm ttsam-demo -f || true
2
  docker run \
3
- -it \
4
- --rm \
5
- --net host \
6
- -v $(pwd):/workspace \
7
- -w /workspace \
8
- --name ttsam-demo \
9
- ttsam-demo \
10
- /usr/local/bin/python /workspace/app.py
 
1
+ #!/bin/bash
2
  docker container rm ttsam-demo -f || true
3
  docker run \
4
+ -it \
5
+ --rm \
6
+ --net host \
7
+ -v $(pwd):/home/user/app \
8
+ --name ttsam-demo \
9
+ ttsam-demo