Building an Edge Inference Container Image (Debian OSs)

This section uses the container image Ubuntu 20.04 as an example to describe how to create a CANN edge inference container image that contains the CANN packages NNRT and Kernels.

This section describes how to customize a Dockerfile to create a CANN container image.

  1. Run the following command to create the ascend-cann folder in any directory (for example, /home):
    1
    mkdir ascend-cann
    
  2. Run the following command to go to the ascend-cann directory:
    1
    cd ascend-cann
    

    Place the NNRT and Kernels packages in the current directory by referring to Software Package Preparation.

  3. Run the vi Dockerfile command to create a Dockerfile and add the following content to the file: You can modify the script based on the OS type and the software package to be installed.
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    ARG BASE=$BASE
    FROM $BASE
    
    WORKDIR /tmp
    COPY . ./
    
    # Set the environment variable of the driver path.
    ARG ASCEND_BASE=/usr/local/Ascend
    ENV LD_LIBRARY_PATH=\
    $ASCEND_BASE/driver/lib64:\
    $ASCEND_BASE/driver/lib64/common:\
    $ASCEND_BASE/driver/lib64/driver:\
    $LD_LIBRARY_PATH
    
    SHELL ["/bin/bash","-c"]
    
    # 1 Installing CANN
    ARG CANN_PKG=Ascend-cann-nnrt_*.run
    ARG KERNEL_PKG=Ascend-cann-kernels-*.run
    RUN chmod +x $CANN_PKG && \
        ./$CANN_PKG --quiet --install --install-path=$ASCEND_BASE --install-for-all && \
        chmod +x $KERNEL_PKG && \
        ./$KERNEL_PKG --quiet --install --install-for-all
    
    # 2 Clean up the environment.
    RUN rm -rf ./*
    

    Run the :wq! command to save the file and exit.

  4. Run the following command in the current directory to create an image:
    1
    docker build -t {image_name}:{new_tag} --build-arg BASE={image_name}:{tag} .
    

    Do not omit . at the end of the command. The following is a command example:

    1
    docker build -t ascend-cann:8.0.0-ubuntu --build-arg BASE=ubuntu:focal .
    
    Table 1 Command parameter description

    Parameter

    Description

    {image_name}:{new_tag}

    Name and tag of the image to be built. You are advised to set {image_name}:{new_tag} in the format of "software package: software package version-container OS-framework type", for example, ascend-cann:8.0.0-ubuntu.

    --build-arg

    Parameters in the Dockerfile.

    {image_name}:{tag}

    {image_name}:{tag} is the OS basic container image of Installation Preparations.