version: '3.9'
x-base_service: &base_service
volumes:
- &v1 /data/comfyui/comfy:/home/ComfyUI/comfy
- &v2 /data/comfyui/custom_nodes:/home/ComfyUI/custom_nodes
- &v3 /data/comfyui/models:/home/ComfyUI/models
- &v4 /data/comfyui/cache:/root/.cache
- &v5 /data/comfyui/input:/home/ComfyUI/input
- &v6 /data/comfyui/output:/home/ComfyUI/output
deploy:
resources:
reservations:
devices:
- driver: nvidia
device_ids: [ '0','1','2','3','4','5','6','7' ]
capabilities: [ gpu ]
services:
auto-0:
<<: *base_service #引用上面的base_service,因为每个任务都需要 用到文件挂载,所以统一卸载base_service中,以后每个任务只要引用就好了
build:
context: .
dockerfile: Dockerfile
ports:
- "9786:7860"
restart: always
image: svd_api_527:
environment:
- DEVICE_ID=1
volumes:
- "/data/hoo/comfyui/comfy:/home/ComfyUI/comfy"
- "/data/hoo/comfyui/custom_nodes:/home/ComfyUI/custom_nodes"
- "/data/hoo/comfyui/models:/home/ComfyUI/models"
- "/data/hoo/comfyui/cache:/root/.cache"
- "/data/hoo/comfyui/input:/home/ComfyUI/input"
- "/data/hoo/comfyui/output:/home/ComfyUI/output"
auto-0 表示任务名称:
build:暂时不是很清楚用法
ports: 这个是端口映射 相当于 docker run 的 -p 9876:7860
image: 容器是哪个镜像的实例
enviornment: 这是是环境变量和 -e 等同,因为你一下子需要在多个GPU上运行,所以 你需要为每个任务启动时传输一个device_id,
enviornment 我目前理解可以和shell脚本搭配使用,你这边传输一个环境变量DEVICE_ID 值为 1,在 shell脚本那里 运行 CUDA_VISIBLE_DEVICE={DEVICE_ID} python main.py
那么 程序在运行时 就是在DEVICE_ID对应的GPU上运行。
因为你要在多张卡上启动多个任务,auto-0 只是第一个任务,重复auto-0的格式 继续第二个,第三个任务。
例如我的第二个任务要在 第 3 张GPU上运行 容器内端口还是 7860,将容器内7860 映射到宿主机的 9877端口
auto-1:
build:
context: .
dockerfile: Dockerfile
ports:
- "9787:7860"
restart: always
image: svd_api_527
environment:
- DEVICE_ID=2
volumes:
- "/data/hoo/comfyui/comfy:/home/ComfyUI/comfy"
- "/data/hoo/comfyui/custom_nodes:/home/ComfyUI/custom_nodes"
- "/data/hoo/comfyui/models:/home/ComfyUI/models"
- "/data/hoo/comfyui/cache:/root/.cache"
- "/data/hoo/comfyui/input:/home/ComfyUI/input"
- "/data/hoo/comfyui/output:/home/ComfyUI/output"