展开代码/data/xiedong/modelscope/docker/ ├── build_image.py # 主构建脚本 ├── Dockerfile.ubuntu # 主 Dockerfile 模板 ├── Dockerfile.extra_install # Python 和基础依赖安装 ├── install.sh # PyTorch/vLLM/FlashAttn 安装脚本 └── rcfiles/ # 配置文件资源
展开代码Builder (基类) └── LLMImageBuilder └── SwiftImageBuilder (第347行) ← 当前使用的构建器
位于 build_image.py:349-364
python展开代码base_image = 'nvidia/cuda:12.8.1-cudnn-devel-ubuntu22.04'
cuda_version = '12.8.1'
torch_version = '2.9.0'
vllm_version = '0.13.0'
lmdeploy_version = '0.10.1'
flashattn_version = '2.8.3'
bash展开代码cd /data/xiedong/modelscope
# 必须设置镜像仓库地址
export DOCKER_REGISTRY="你的镜像仓库地址"
bash展开代码python docker/build_image.py \ --image_type swift \ --python_version 3.11.9 \ --modelscope_version 1.33.0 \ --swift_branch main \ --dry_run 1
✅ 生成的 Dockerfile 在当前目录: ./Dockerfile
bash展开代码python docker/build_image.py \ --image_type swift \ --python_version 3.11.9 \ --modelscope_version 1.33.0 \ --swift_branch main \ --dry_run 0
| 参数 | 说明 | 默认值 |
|---|---|---|
--image_type | 镜像类型 | swift |
--python_version | Python 版本 | 3.10.14 |
--ubuntu_version | Ubuntu 版本 | 22.04 |
--torch_version | PyTorch 版本 | 2.9.0 |
--cuda_version | CUDA 版本 | 12.8.1 |
--vllm_version | vLLM 版本 | 0.13.0 |
--flashattn_version | FlashAttn 版本 | 2.8.3 |
--swift_branch | ms-swift git 分支 | main |
--modelscope_branch | modelscope git 分支 | master |
--modelscope_version | 镜像 tag 中的版本号 | 9.99.0 |
--dry_run | 1=只生成Dockerfile, 0=实际构建 | 0 |
展开代码{DOCKER_REGISTRY}:ubuntu22.04-cuda12.8.1-py311-torch2.9.0-1.33.0-swift-test
Dockerfile.extra_install)Dockerfile.ubuntu)pip install .[llm])install.sh 安装 PyTorch/vLLM/FlashAttnDockerfile.ubuntu:78-88)/root/.cache/modelscope/_github/bash展开代码python docker/build_image.py --image_type swift --dry_run 1
bash展开代码cat ./Dockerfile
# 按需修改 Dockerfile
bash展开代码docker build -t my-swift-image:latest -f Dockerfile .
bash展开代码docker push my-swift-image:latest
💡 提示: 建议先使用
--dry_run 1参数测试生成 Dockerfile,确认无误后再进行实际构建。


本文作者:Dong
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC。本作品采用《知识共享署名-非商业性使用 4.0 国际许可协议》进行许可。您可以在非商业用途下自由转载和修改,但必须注明出处并提供原作者链接。 许可协议。转载请注明出处!