Using a Custom Image to Enhance the Job Running Environment
Scenario
To enhance the functions and performance of Spark and Flink jobs, you can create custom images by downloading the base images 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 base images provided by DLI must be used to create custom images.
- You cannot modify the DLI components and directories in the base images.
- Only Spark Jar and Flink Jar jobs are supported.
Use Process
- Obtain DLI base images.
- Use Dockerfile to pack dependencies (files, JAR files, or software) required for job execution into the base image to create a custom image.
- Publish the custom image to SoftWare Repository for Container (SWR).
- On the DLI job editing page, select the created image and run the job.
- Check the job execution status.
Obtaining DLI Base Images
Image Type |
Architecture |
URL |
---|---|---|
General image |
x86 |
swr.ap-southeast-3.myhuaweicloud.com/dli-public/spark_notebook-x86_64:3.3.1-2.3.7.1720240419835647952528832.202404250955 |
General image |
Arm |
swr.ap-southeast-3.myhuaweicloud.com/dli-public/spark_notebook-aarch64:3.3.1-2.3.7.1720240419835647952528832.202404250955 |
Notebook image |
x86 |
swr.ap-southeast-3.myhuaweicloud.com/dli-public/spark_general-x86_64:3.3.1-2.3.7.1720240419835647952528832.202404250955 |
Notebook image |
Arm |
swr.ap-southeast-3.myhuaweicloud.com/dli-public/spark_general-aarch64:3.3.1-2.3.7.1720240419835647952528832.202404250955 |
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.
- Prepare the container environment.
For details, see "Step 1: Install the Container Engine" in Uploading an Image Through a Container Engine Client.
- Log in to the prepared container environment as user root and run a command to obtain the base image.
In this example, the Spark base image is used and downloaded to the container image environment in 1 by running the following command:
docker pull Address for downloading the base image
For details about the address, see Using a Custom Image to Enhance the Job Running Environment.
For example, to download the Spark base image, run the following command:docker pull swr.xxx/dli-public/spark_general-x86_64:3.3.1-2.3.7.1720240419835647952528832.202404250955
- Access SWR.
- Log in to the SWR management console.
- 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.
- Run the login command on the VM where the container engine is installed.
- Create an organization. If an organization has been created, skip this step.
- Log in to the SWR management console.
- In the navigation pane on the left, choose Organization Management. On the displayed page, click Create Organization in the upper right corner.
- Enter the organization name and click OK.
- 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 base 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 base image. USER omm
The following steps are included:
- Set the available repository address of pip.
- Use pip3 to install the TensorFlow algorithm package.
- Copy the content in the temporary image builder where the algorithm package is installed to the base image (this step is to reduce the image size) to generate the final custom image.
- 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 base image path] -f Dockerfile .
The DLI base image path is the image path in Obtaining DLI Base Images.
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 .
- 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
- 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
- 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. Set 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.
- 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.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot