Building an Edge Inference Container Image (openEuler Series)
This section uses the container image openEuler 20.03 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.
- Run the following command to create the ascend-cann folder in any directory (for example, /home):
1mkdir ascend-cann - Run the following command to go to the ascend-cann directory:
1cd ascend-cann
Place the NNRT and Kernels packages in the current directory by referring to Software Package Preparation.
- 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 27 28 29
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. Preparing for the environment RUN yum install -y shadow-utils # 2 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 # 3 Clean up the environment. RUN rm -rf ./*
Run the :wq! command to save the file and exit.
- Run the following command in the current directory to create an image:
1docker 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:
1docker build -t ascend-cann:8.0.0-openEuler --build-arg BASE=openeuler-20.03-lts-sp2:latest .
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", for example, ascend-cann:8.0.0-openEuler.
--build-arg
Parameters in the Dockerfile.
{image_name}:{tag}
{image_name}:{tag} is the OS basic container image of Installation Preparations.