Help Center/ Data Lake Insight/ User Guide/ Creating a Custom Image
Updated on 2024-08-20 GMT+08:00

Creating a Custom Image

Use Cases

To enhance the functions and performance of Spark and Flink jobs, you can create custom images by downloading the basic image provided by DLI and adding dependencies (files, JAR files, or software) and private capabilities required for job execution. This changes the container runtime environment for the jobs.

For example, you can add a Python package or C library related to machine learning to a custom image to help you extend functions.

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

Notes and Constraints

  • The basic images provided by DLI must be used to create custom images.
  • You cannot modify the DLI components and directories in the basic images.
  • Only Spark and Flink Jar jobs are supported.

Use Process

Figure 1 Process of using a custom image
  1. Obtain DLI basic images.
  2. Use Dockerfile to pack dependencies (files, JAR files, or software) required for job execution into the basic image to create a custom image.
  3. Publish the custom image to SoftWare Repository for Container (SWR).
  4. On the DLI job editing page, select the created image and run the job.
  5. Check the job execution status.

Obtaining DLI Basic Images

Table 1 Obtaining DLI basic images

Image Type

Architecture

General image

x86

General image

Arm

Notebook image

x86

Notebook image

Arm

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. Prepare the container environment.

    For details, see "Step 1: Install the Container Engine" in Uploading an Image Through a Container Engine Client.

  2. Log in to the prepared container environment as user root and run a command to obtain the basic image.

    In this example, the Spark basic image is used and downloaded to the container image environment in 1 by running the following command:

    docker pull Address for downloading the basic image

    For details about the address, see Creating a Custom Image.

    For example, to download the Spark basic image, run the following command:
    docker pull swr.xxx/dli-public/spark_general-x86_64:3.3.1-2.3.7.1720240419835647952528832.202404250955

  3. Access SWR.

    1. Log in to the SWR management console.
    2. In the navigation pane on the left, choose Dashboard and click Generate Login Command in the upper right corner. On the displayed page, click to copy the login command.
    3. Run the login command on the VM where the container engine is installed.

  4. Create an organization. If an organization has been created, skip this step.

    1. Log in to the SWR management console.
    2. In the navigation pane on the left, choose Organization Management. On the displayed page, click Create Organization in the upper right corner.
    3. Enter the organization name and click OK.

  5. Write a Dockerfile.

    vi Dockerfile

    Pack TensorFlow into the image as follows:

    ARG BASE_IMG=swr.xxx/dli-public/spark_general-x86_64:3.3.1-2.3.7.1720240419835647952528832.202404250955//Replace xxx with the URL of the basic image.
    
    FROM ${BASE_IMG} as builder
    USER omm //Run this command as user omm.
    RUN set -ex && \
        mkdir -p /home/omm/.pip && \
        pip3 install tensorflow==1.13.1 \
        --user --no-cache-dir  --trusted-host pypi.cloudartifact.dgg.dragon.tools.huawei.com \
        -i https://pypi.cloudartifact.dgg.dragon.tools.huawei.com/artifactory/api/pypi/cbu-pypi-public/simple
    Copy the content to the basic image.
    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.

  6. Use Dockerfile to generate a custom image.

    Format of the image packaging command:
    docker build -t [Custom organization name]/[Custom image name]: [Image version] --build-arg BASE_IMG= [DLI basic image path] -f Dockerfile .

    The DLI basic image path is the image path in Table 1.

    The following is an example:
    docker build -t mydli/spark:2.4 --build-arg BASE_IMG=swr.xxx/dli-public/spark_general-x86_64:3.3.1-2.3.7.1720240419835647952528832.202404250955 -f Dockerfile .

  7. Add a tag to the custom image.

    docker tag [Organization name]/[Image name]:[Image version][Image repository address]/[Organization name]/[Image name:version] in 6

    The following is an example:
    docker tag mydli/spark:2.4 swr.xxx/testdli0617/spark:2.4.5.tensorflow

  8. Upload the custom image.

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

    Set [Image repository address]/[Organization name]/[Image name:Version] the same as those in 7.

    The following is an example:
    docker push swr.xxx/testdli0617/spark:2.4.5.tensorflow

  9. 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 you select a non- shared image, the system displays a message indicating that the image is not authorized. You can use the image only after it is authorized. Click Authorize as prompted as shown in Figure 3. Configure other job execution parameters and execute the job.
      Figure 2 Selecting a custom image on the DLI Spark job editing page
      Figure 3 Authorizing a Spark job image
      Figure 4 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 Flink Jar Job.