From 9e89bd2edb9d2431128b60bf4cc5e4ca0660dddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=9E=E6=89=AC?= <3280204+ycrao@users.noreply.github.com> Date: Thu, 21 Nov 2024 18:04:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E9=80=9F=E4=B8=AD=E5=9B=BD=E5=A4=A7?= =?UTF-8?q?=E9=99=86=E5=9C=B0=E5=8C=BA=20docker=20=E9=95=9C=E5=83=8F=20(#5?= =?UTF-8?q?75)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 中国大陆地址镜像适配 * update * 更多说明 * more comments * update docker run cmd * Update README-zh.md * change port --- Dockerfile-for-Mainland-China | 39 ++++++++++++++++++++++++ README-zh.md | 56 +++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 Dockerfile-for-Mainland-China diff --git a/Dockerfile-for-Mainland-China b/Dockerfile-for-Mainland-China new file mode 100644 index 0000000..bc183b9 --- /dev/null +++ b/Dockerfile-for-Mainland-China @@ -0,0 +1,39 @@ +FROM nvcr.io/nvidia/pytorch:24.07-py3 + +EXPOSE 28000 + +ENV TZ=Asia/Shanghai +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && apt update && apt install python3-tk -y + +RUN mkdir /app + +WORKDIR /app +RUN git clone --recurse-submodules https://github.com/Akegarasu/lora-scripts + +WORKDIR /app/lora-scripts + +# 设置 Python pip 软件包国内镜像代理 +RUN pip config set global.index-url 'https://pypi.tuna.tsinghua.edu.cn/simple' && \ + pip config set install.trusted-host 'pypi.tuna.tsinghua.edu.cn' + +# 初次安装依赖 +RUN pip install xformers==0.0.27.post2 --no-deps && pip install -r requirements.txt + +# 更新 训练程序 stable 版本依赖 +WORKDIR /app/lora-scripts/scripts/stable +RUN pip install -r requirements.txt + +# 更新 训练程序 dev 版本依赖 +WORKDIR /app/lora-scripts/scripts/dev +RUN pip install -r requirements.txt + +WORKDIR /app/lora-scripts + +# 修正运行报错以及底包缺失的依赖 +# ref +# - https://soulteary.com/2024/01/07/fix-opencv-dependency-errors-opencv-fixer.html +# - https://blog.csdn.net/qq_50195602/article/details/124188467 +RUN pip install opencv-fixer==0.2.5 && python -c "from opencv_fixer import AutoFix; AutoFix()" \ + pip install opencv-python-headless && apt install ffmpeg libsm6 libxext6 libgl1 -y + +CMD ["python", "gui.py", "--listen"] \ No newline at end of file diff --git a/README-zh.md b/README-zh.md index 28bb9e8..34cea43 100644 --- a/README-zh.md +++ b/README-zh.md @@ -82,6 +82,62 @@ git clone --recurse-submodules https://github.com/Akegarasu/lora-scripts 运行 `bash run_gui.bash`,程序将自动打开 [http://127.0.0.1:28000](http://127.0.0.1:28000) +### Docker + +#### 编译镜像 + +```bash +# 国内镜像优化版本 +# 其中 akegarasu_lora-scripts:latest 为镜像及其 tag 名,根据镜像托管服务商实际进行修改 +docker build -t akegarasu_lora-scripts:latest -f Dockfile-for-Mainland-China . +docker push akegarasu_lora-scripts:latest +``` + +#### 使用镜像 + +> 提供一个本人已打包好并推送到 `aliyuncs` 上的镜像,此镜像压缩归档大小约 `10G` 左右,请耐心等待拉取。 + +```bash +docker run --gpus all -p 28000:28000 -p 6006:6006 registry.cn-hangzhou.aliyuncs.com/go-to-mirror/akegarasu_lora-scripts:latest +``` + +或者使用 `docker-compose.yaml` 。 + +```yaml +services: + lora-scripts: + container_name: lora-scripts + build: + context: . + dockerfile: Dockerfile-for-Mainland-China + image: "registry.cn-hangzhou.aliyuncs.com/go-to-mirror/akegarasu_lora-scripts:latest" + ports: + - "28000:28000" + - "6006:6006" + # 共享本地文件夹(请根据实际修改) + #volumes: + # - "/data/srv/lora-scripts:/app/lora-scripts" + # 共享 comfyui 大模型 + # - "/data/srv/comfyui/models/checkpoints:/app/lora-scripts/sd-models/comfyui" + # 共享 sd-webui 大模型 + # - "/data/srv/stable-diffusion-webui/models/Stable-diffusion:/app/lora-scripts/sd-models/sd-webui" + environment: + - HF_HOME=huggingface + - PYTHONUTF8=1 + security_opt: + - "label=type:nvidia_container_t" + runtime: nvidia + deploy: + resources: + reservations: + devices: + - driver: nvidia + device_ids: ['0'] + capabilities: [gpu] +``` + +关于容器使用 GPU 相关依赖安装问题,请自行搜索查阅资料解决。 + ## 通过手动运行脚本的传统训练方式 ### Windows