Using Custom Images

Scenarios

You can use the Spark or Flink basic images provided by DLI to package the dependencies (files, JAR packages, or software) required into an image using Dockerfile, generate a custom image, and release the image to SWR. On the DLI job editing page, select the generated image and run the job. You can embed private capabilities into custom images to enhance the functions and performance of jobs.

To use the custom image function, you need to have basic knowledge of Docker.

Restrictions

  • Only containerized queues are supported.
  • Only JAR jobs (user-defined Spark and Flink jobs) are supported.

Procedure for Creating a Custom Image

The following describes how to package TensorFlow into an image to generate a custom image with TensorFlow installed. Then, you can use the image to run jobs in DLI.

  1. Obtain basic images.

    Run the following command to obtain the basic image.

    Syntax:

    docker pull [SWR repository address]/[organization name]/[image name]:[image tag]

    Example:

    docker pull swr.cn-north-1.huaweicloud.com/dli/spark:2.3.2-1.0.0-euler-2.9-x86_64
    Table 1 Basic images

    Organization Name

    Image Name

    Image Tag

    dli

    spark

    2.3.2-1.0.0-euler-2.9-20.04-x86_64

    2.3.2-1.0.0-euler-2.9-aarch64

    flink

    1.10-1.0.0-euler-2.9-x86_64

    1.10-1.0.0-euler-2.9-aarch64

    Image naming description:

    <swr-registry>/<org>/<compoent>:<component-ver>-<imagever>-<os>-<os-ver>-<arch>

    • swr-registry: SWR repository address, for example, swr.cn-north-1.huaweicloud.com.
    • org: Organization name. The default value is dli.
    • component: Image name, the value can be spark or flink.
    • component-ver: Image version. The value for Spark is 2.3.x or 2.4.x and for Flink is 1.10
    • imagever: 1.0.0, in ascending order
    • os: Euler
    • os-ver: OS version
    • arch: x86_64 or aarch64

  2. Write a Dockerfile.

    An example of the Dockerfile content is as follows:

    ARG BASE_IMG=spark:latest
    
    FROM ${BASE_IMG} as builder
    USER root
    RUN set -ex && \
        mkdir -p /root/.pip && \
        echo "[global]" >> /root/.pip/pip.conf && \
        echo "index-url = https://mirrors.huaweicloud.com/repository/pypi/simple" >> /root/.pip/pip.conf && \
        pip3 install --user --no-cache-dir tensorflow==1.13.1
    
    FROM ${BASE_IMG}
    USER root
    COPY --from=builder --chown=omm:ficommon /root/.local /home/omm/.local
    USER omm

    The following steps are included:

    1. Set the available repository address of pip.
    2. Use pip3 to install the TensorFlow algorithm package.
    3. Copy the content in the temporary image builder where the algorithm package is installed to the basic image (this step is to reduce the image size) to generate the final custom image.

  3. Use Dockerfile to generate a custom image.

    Format of the image packaging command:
    docker build -t [Organization name]/[Image name]: [Image version] --build-arg BASE_IMG= [DLI basic image path] -f Dockerfile
    The following is an example of the image packaging command:
    docker build -t mydli/spark:1.0 --build-arg BASE_IMG=swr.cn-north-1.huaweicloud.com/dli/spark:2.3.2-1.0.0-euler-2.9-x86_64 -f Dockerfile . 

  4. Upload the custom image to the SoftWare Repository for Container (SWR) service. SWR provides two upload modes:

    • Uploading an image through a container engine client
      1. Access SWR.

        Syntax:

        docker login -u xxxxxx@xxxxxxx -p xxxxxxxxxxxxx
      2. Tag the Spark image by running the following command:

        Syntax:

        docker tag [Image name:tag] [Image repository address]/[Organization name]/[Image name:tag]

        Sample command:

        docker tag mydli/spark:1.0 swr.cn-north-1.huaweicloud.com/mydli/spark:1.0
      3. Push the image to the image repository.

        Syntax:

        docker push [Image repository address]/[Organization name]/[Image name:tag]

        Sample command:

        docker push swr.cn-north-1.huaweicloud.com/mydli/spark:1.0 

      For details about how to upload an image using a client, see the SoftWare Repository for Container User Guide.

    • Uploading an image through SWR console

      For details about how to upload images on the page, see the SoftWare Repository for Container User Guide.

  5. When submitting a Spark or Flink JAR job in DLI, select a custom image.

    • Open the Spark job or Flink job editing page on the management console, select the uploaded and shared image from the custom image list, and run the job. If no shared image is available, click Authorize and set related parameters to run the job.
      Figure 1 Selecting a custom image on the DLI Spark job editing page
      Figure 2 Selecting a custom image on the DLI Flink Jar job editing page
    • Specify the image parameter in job parameters on API to use a custom image to run a job. For details about Spark jobs, see Creating a Batch Processing Job. For details about Flink JAR jobs, see Creating a Custom Flink Job.