更新时间:2025-12-17 GMT+08:00
分享

准备标注镜像

步骤一:构建标注镜像

  1. 获取模型和启动代码。

    准备模型已将导出的mindir模型放置于/home/driving_model,将AscendCloud-ACD-6.5.911-xxx.zip包上传到节点机器/home/driving_model,执行命令解压:

    unzip AscendCloud-ACD-6.5.911-xxx.zip
  2. 编辑Dockerfile文件。

    将yolov7 mindir模型、启动代码及其他相关需要打包到镜像的内容一并编辑到Dockerfile中。Dockerfil文件内容如下:

    # 指定基础镜像
    FROM swr.cn-east-4.myhuaweicloud.com/atelier/pytorch_ascend:pytorch_2.5.1-cann_8.2.rc2-py_3.11-hce_2.0.2509-aarch64-snt9b-20251105194139-a70c13c
    
    # 设置用户
    USER root
    
    # 设置工作目录
    WORKDIR /
    
    # 设置环境变量,如代理等
    ENV http_proxy=
    ENV https_proxy=
    ENV proxy=
    
    # 安装rclone
    RUN curl -k https://rclone.org/install.sh > install.sh && \
        sed -i.bak 's/curl /curl -k /g' install.sh && \
        bash install.sh && \
        rm -f install.sh
    
    # 安装依赖,根据需要调整版本和依赖模块
    RUN pip install matplotlib==3.9.4 pandas==2.0.3 shapely==2.0.7
    RUN pip install decorator==5.2.1 sympy==1.14.0 attr==0.3.2 attrs==25.3.0 psutil==7.0.0 imageio==2.37.0 seaborn==0.13.2 terminaltables==3.1.10
    RUN pip install imagesize==1.4.1 polygraphy==0.48.1 onnx==1.16.2 onnx_graphsurgeon==0.5.2 loguru==0.7.0  hydra-core==1.3.2 numba==0.56.4 pathos==0.3.2 && \
        pip install opencv-python==4.10.0.84 protobuf==3.20.2 onnxsim==0.4.24 &&  \
        pip install cvxpy==1.5.3 pympler==1.1 absl-py==2.1.0 easydict==1.13 icecream==2.1.3
    
    # 拷贝代码,比如启动代码等
    COPY ./code/ /xx/code/
    
    # 拷贝模型
    COPY /model/output_model.mindir /model/
    
    # copy测试数据,便于在镜像中快速验证,根据实际需要修改或删除
    COPY /xx/ /xx/
  1. 执行以下命令制作标注镜像。安装过程git clone需要连接互联网,请确保机器可以访问公网。
    nerdctl --namespace k8s.io build  -f ./Dockerfile --build-arg install_type=xxx -t <镜像名称>:<版本名称>  .
    nerdctl build 会去镜像仓库拉取镜像,不会直接使用本地镜像。构建前可用 nerdctl pull 命令拉取测试镜像是否能拉取成功。
    • <镜像名称>:<版本名称>:定义镜像名称。示例:pytorch_2_3_ascend:20251125
    • 记住使用Dockerfile创建的新镜像名称,后续使用 ${dockerfile_image_name} 表示。

步骤二:在节点机器中containerd登录

在SWR中单击右上角的“登录指令”,然后在跳出的登录指定窗口,单击复制临时登录指令。

由于使用的容器引擎是containerd,不再是docker,因此需要改写复制的登录指令,将docker进行替换,使用nerdctl工具。
# docker login 替换为:
nerdctl login

步骤三:修改并上传镜像至SWR

  1. 为镜像打tag。
    nerdctl --namespace k8s.io tag ${dockerfile_image_name} <镜像仓库地址>/<组织名称>/<镜像名称>:<版本名称>

    参数说明:

    • ${dockerfile_image_name}:在步骤一:构建标注镜像中使用Dockerfile创建的新镜像名称。
    • <镜像仓库地址>:可在SWR控制台上查询,容器镜像服务中登录指令末尾的域名即为镜像仓库地址。
    • <组织名称>:参考创建组织对应的组织名称。示例:GROUP_NAME
    • <镜像名称>:<版本名称>:定义镜像名称。示例:pytorch_2_3_ascend:20251125

    示例:

    nerdctl --namespace k8s.io tag  ${dockerfile_image_name}  swr.cn-southwest-2.myhuaweicloud.com/GPOUP_NAME/pytorch_2_3_ascend:20251125
  2. 上传镜像至镜像仓库。
    nerdctl --namespace k8s.io push <镜像仓库地址>/<组织名称>/<镜像名称>:<版本名称>

    示例:

    nerdctl --namespace k8s.io push swr.cn-southwest-2.myhuaweicloud.com/GPOUP_NAME/pytorch_2_3_ascend:20251125

相关文档