Copied.
ma-cli image Commands for Building Images
The ma-cli image command can be used to obtain registered images, obtain or load image creation templates, create images using Dockerfiles, obtain or clear image creation caches, register or deregister images, and debug whether images can be used in notebook instances. For details, run the ma-cli image -h command.
Commands for Creating an Image
$ ma-cli image -h Usage: ma-cli image [OPTIONS] COMMAND [ARGS]... Obtain registered images, register or unregister images, debug images, and create images in Notebook. Options: -H, -h, --help Show this message and exit. Commands: add-template, at List build-in dockerfile templates. build Build docker image in Notebook. debug Debug SWR image as a Notebook in ECS. df Query disk usage. get-image, gi Query registered image in ModelArts. get-template, gt List build-in dockerfile templates. prune Prune image build cache. register Register image to ModelArts. unregister Unregister image from ModelArts.
| Command | Description |
|---|---|
| get-template | Obtain an image creation template. |
| add-template | Load an image creation template. |
| get-image | Obtain registered ModelArts images. |
| register | Register SWR images with ModelArts image management. |
| unregister | Deregister a registered image from ModelArts image management. |
| build | Build an image using a Dockerfile (only supported in ModelArts Notebook). |
| df | Obtain image creation cache, which can only be used in ModelArts notebook. |
| prune | Clear image creation cache, which can only be used in ModelArts notebook. |
| debug | Debug an SWR image on an ECS to check whether the image can be used in ModelArts notebook. (Only the ECSs with Docker installed can be used.) |
Using ma-cli image get-template to Query an Image Building Template
ma-cli provides some common image building templates, which contain the guidance for developing Dockerfiles on ModelArts notebook.
$ ma-cli image get-template -h Usage: ma-cli image get-template [OPTIONS] List build-in dockerfile templates. Example: # List build-in dockerfile templates ma-cli image get-template [--filer <filter_info>] [--page-num <yourPageNum>] [--page-size <yourPageSize>] Options: --filter TEXT filter by keyword. -pn, --page-num INTEGER RANGE Specify which page to query. [x>=1] -ps, --page-size INTEGER RANGE The maximum number of results for this query. [x>=1] -D, --debug Debug Mode. Shows full stack trace when error occurs. -P, --profile TEXT CLI connection profile to use. The default profile is "DEFAULT". -H, -h, --help Show this message and exit. (PyTorch-1.4) [ma-user work]$
| Parameter | Data Type | Mandatory | Description |
|---|---|---|---|
| --filter | String | No | Template name keyword for filtering templates. |
| -pn / --page-num | Int | No | Image page index. The default value is page 1. |
| -ps / --page-size | Int | No | Number of images displayed on each page. The default value is 20. |
Example: Obtain an image building template.
ma-cli image get-template

Using ma-cli image add-template to Load an Image Building Template
The add-template command is used to load image templates to a specified folder. By default, the path where the current command is located is used,
for example, ${current_dir}/.ma/${template_name}/. You can also use --dest to specify the path. If a template folder with the same name already exists in the target path, use the --force | -f parameter to forcibly overwrite the existing template folder.
$ ma-cli image add-template -h Usage: ma-cli image add-template [OPTIONS] TEMPLATE_NAME Add buildin dockerfile templates into disk. Example: # List build-in dockerfile templates ma-cli image add-template customize_from_ubuntu_18.04_to_modelarts --force Options: --dst TEXT target save path. -f, --force Override templates that has been installed. -D, --debug Debug Mode. Shows full stack trace when error occurs. -P, --profile TEXT CLI connection profile to use. The default profile is "DEFAULT". -h, -H, --help Show this message and exit.
| Parameter | Data Type | Mandatory | Description |
|---|---|---|---|
| --dst | String | No | Target path for loading a template. The current path is used by default. |
| -f / --force | Bool | No | Whether to forcibly overwrite an existing template with the same name. By default, the template is not overwritten. |
Example: Load the customize_from_ubuntu_18.04_to_modelarts image building template.
ma-cli image add-template customize_from_ubuntu_18.04_to_modelarts

Using ma-cli image get-image to Query Registered ModelArts Images
A path to a base image is provided in a Dockerfile typically. Public images and SWR public or private images can be obtained from open-source image repositories such as Docker Hub. ma-cli allows you to obtain ModelArts preset images, registered images, and their SWR addresses.
$ma-cli image get-image -h
Usage: ma-cli image get-image [OPTIONS]
Get registered image list.
Example:
# Query images by image type and only image id, show name and swr_path
ma-cli image get-image --type=DEDICATED
# Query images by image id
ma-cli image get-image --image-id ${image_id}
# Query images by image type and show more information
ma-cli image get-image --type=DEDICATED -v
# Query images by image name
ma-cli image get-image --filter=torch
Options:
-t, --type [BUILD_IN|DEDICATED|ALL]
Image type(default ALL)
-f, --filter TEXT Image name to filter
-v, --verbose Show detailed information on image.
-i, --image-id TEXT Get image details by image id
-n, --image-name TEXT Get image details by image name
-wi, --workspace-id TEXT The workspace where you want to query image(default "0")
-pn, --page-num INTEGER RANGE Specify which page to query [x>=1]
-ps, --page-size INTEGER RANGE The maximum number of results for this query [x>=1]
-C, --config-file PATH Configure file path for authorization.
-D, --debug Debug Mode. Shows full stack trace when error occurs.
-P, --profile TEXT CLI connection profile to use. The default profile is "DEFAULT".
-H, -h, --help Show this message and exit. | Parameter | Data Type | Mandatory | Description |
|---|---|---|---|
| -t / --type | String | No | Type of the images to be obtained. The options are BUILD_IN, DEDICATED, and ALL.
|
| -f / --filter | String | No | Image name keyword for filtering images. |
| -v / --verbose | Bool | No | Whether to display detailed information. It is disabled by default. |
| -i / --image-id | String | No | ID of the image whose details are to be obtained. |
| -n / --image-name | String | No | Name of the image whose details are to be obtained. |
| -wi / --workspace-id | String | No | Workspace in which the image information is to be obtained. |
| -pn / --page-num | Int | No | Image page index. The default value is page 1. |
| -ps / --page-size | Int | No | Number of images displayed on each page. The default value is 20. |
Example: Obtain custom images registered with ModelArts.
ma-cli image get-image --type=DEDICATED

Using ma-cli image build to Build an Image in ModelArts Notebook
Run the ma-cli image build command to build an image based on a specified Dockerfile. This command is available only on ModelArts notebook instances.
$ ma-cli image build -h Usage: ma-cli image build [OPTIONS] FILE_PATH Build docker image in Notebook. Example: # Build a image and push to SWR ma-cli image build .ma/customize_from_ubuntu_18.04_to_modelarts/Dockerfile -swr my_organization/my_image:0.0.1 # Build a image and push to SWR, dockerfile context path is current dir ma-cli image build .ma/customize_from_ubuntu_18.04_to_modelarts/Dockerfile -swr my_organization/my_image:0.0.1 -context . # Build a local image and save to local path and OBS ma-cli image build .ma/customize_from_ubuntu_18.04_to_modelarts/Dockerfile --target ./build.tar --obs-path obs://bucket/object --swr-path my_organization/my_image:0.0.1 Options: -t, --target TEXT Name and optionally a tag in the 'name:tag' format. -swr, --swr-path TEXT SWR path without swr endpoint, eg:organization/image:tag. [required] --context DIRECTORY build context path. -arg, --build-arg TEXT build arg for Dockerfile. -obs, --obs-path TEXT OBS path to save local built image. -f, --force Force to overwrite the existing swr image with the same name and tag. -C, --config-file PATH Configure file path for authorization. -D, --debug Debug Mode. Shows full stack trace when error occurs. -P, --profile TEXT CLI connection profile to use. The default profile is "DEFAULT". -H, -h, --help Show this message and exit.
| Parameter | Data Type | Mandatory | Description |
|---|---|---|---|
| FILE_PATH | String | Yes | Path where the Dockerfile is stored. |
| -t / --target | String | No | Local path for storing the generated TAR package. The current directory is used by default. |
| -swr / --swr-path | String | Yes | SWR image name, which is in the format of "organization/image_name:tag". This parameter can be omitted when a TAR package is saved for building an image. |
| --context | String | No | Context used for copying data when a Dockerfile is used. |
| -arg / --build-arg | String | No | Parameter for building an image. If there are multiple parameters, run --build-arg VERSION=18.04 --build-arg ARCH=X86_64. |
| -obs / --obs-path | String | No | OBS path for automatically uploading the generated TAR package. |
| -f / --force | Bool | No | Whether to forcibly overwrite an existing SWR image with the same name. By default, the SWR image is not overwritten. |
Example: Build an image in ModelArts notebook.
ma-cli image build .ma/customize_from_ubuntu_18.04_to_modelarts/Dockerfile -swr notebook_test/my_image:0.0.1
In this command, .ma/customize_from_ubuntu_18.04_to_modelarts/Dockerfile is the path where the Dockerfile is stored, and notebook_test/my_image:0.0.1 is the SWR path of the new image.

Using ma-cli image df to Obtain Image Building Caches in ModelArts Notebook
Run the ma-cli image df command to obtain image creation caches. This command is available only on ModelArts notebook instances.
$ ma-cli image df -h Usage: ma-cli image df [OPTIONS] Query disk usage used by image-building in Notebook. Example: # Query image disk usage ma-cli image df Options: -v, --verbose Show detailed information on disk usage. -D, --debug Debug Mode. Shows full stack trace when error occurs. -h, -H, --help Show this message and exit.
| Parameter | Data Type | Mandatory | Description |
|---|---|---|---|
| -v / --verbose | Bool | No | Whether to display detailed information. It is disabled by default. |
ma-cli image df

ma-cli image df --verbose

Using ma-cli image prune to Clear Image Building Caches in ModelArts Notebook
Run the ma-cli image prune command to clear image creation caches. This command is available only on ModelArts notebook instances.
$ ma-cli image prune -h Usage: ma-cli image prune [OPTIONS] Prune image build cache by image-building in Notebook. Example: # Prune image build cache ma-cli image prune Options: -ks, --keep-storage INTEGER Amount of disk space to keep for cache below this limit (in MB) (default: 0). -kd, --keep-duration TEXT Keep cache newer than this limit, support second(s), minute(m) and hour(h) (default: 0s). -v, --verbose Show more verbose output. -D, --debug Debug Mode. Shows full stack trace when error occurs. -h, -H, --help Show this message and exit.
| Parameter | Data Type | Mandatory | Description |
|---|---|---|---|
| -ks / --keep-storage | Int | No | Size of the cache to be retained, in MB. The default value is 0, indicating that all caches will be cleared. |
| -kd / --keep-duration | String | No | Duration in which the caches are to be retained. The unit can be s (second), m (minute), or h (hour). The default value is 0s, indicating that all caches will be cleared. |
| -v / --verbose | Bool | No | Whether to display detailed information. It is disabled by default. |
Example: Retain 1 MB of image caches not to be cleared.
ma-cli image prune -ks 1

Using ma-cli image register to Register an SWR Image with ModelArts Image Management
After an image is debugged, run the ma-cli image register command to register it with ModelArts image management so that it can be used in ModelArts.
$ma-cli image register -h
Usage: ma-cli image register [OPTIONS]
Register image to ModelArts.
Example:
# Register image into ModelArts service
ma-cli image register --swr-path=xx
# Share SWR image to DLI service
ma-cli image register -swr xx -td
# Register image into ModelArts service and specify architecture to be 'AARCH64'
ma-cli image register --swr-path=xx --arch AARCH64
Options:
-swr, --swr-path TEXT SWR path without swr endpoint, eg:organization/image:tag. [required]
-a, --arch [X86_64|AARCH64] Image architecture (default: X86_64).
-s, --service [NOTEBOOK|MODELBOX]
Services supported by this image(default NOTEBOOK).
-rs, --resource-category [CPU|GPU|ASCEND]
The resource category supported by this image (default: CPU and GPU).
-wi, --workspace-id TEXT The workspace to register this image (default: "0").
-v, --visibility [PUBLIC|PRIVATE]
PUBLIC: every user can use this image. PRIVATE: only image owner can use this image (Default: PRIVATE).
-td, --to-dli Register swr image to DLI, which will share SWR image to DLI service.
-d, --description TEXT Image description (default: "").
-C, --config-file PATH Configure file path for authorization.
-D, --debug Debug Mode. Shows full stack trace when error occurs.
-P, --profile TEXT CLI connection profile to use. The default profile is "DEFAULT".
-h, -H, --help Show this message and exit. | Parameter | Data Type | Mandatory | Description |
|---|---|---|---|
| -swr / --swr-path | String | Yes | SWR path to the image to be registered. |
| -a / --arch | String | No | Architecture of the image to be registered. The value can be X86_64 or AARCH64. The default value is X86_64. |
| -s / --service | String | No | Service type of the image to be registered. The value can be NOTEBOOK or MODELBOX. The default value is NOTEBOOK. You can also specify multiple values, for example, -s NOTEBOOK -s MODELBOX. |
| -rs / --resource-category | String | No | Resource type that can be used by the image to be registered. The default values are CPU and GPU. |
| -wi / --workspace-id | String | No | Workspace to which the image is to be registered. The default workspace ID is 0. |
| -v / --visibility | Bool | No | Visibility of the image to be registered. The value can be PRIVATE (visible only to the image owner) or PUBLIC (visible to all users). The default value is PRIVATE. |
| -td / --to-dli | Bool | No | Whether to register the image with DLI. |
| -d/ --description | String | No | Description of the image. By default, this parameter is left blank. |
Example: Register an SWR image with ModelArts.
ma-cli image register --swr-path=xx

Using ma-cli image unregister to Deregister an Image
Run the ma-cli image unregister command to deregister an image from ModelArts.
$ ma-cli image unregister -h Usage: ma-cli image unregister [OPTIONS] Unregister image from ModelArts. Example: # Unregister image ma-cli image unregister --image-id=xx # Unregister image and delete it from swr ma-cli image unregister --image-id=xx -d Options: -i, --image-id TEXT Unregister image details by image id. [required] -d, --delete-swr-image Delete the image from swr. -C, --config-file PATH Configure file path for authorization. -D, --debug Debug Mode. Shows full stack trace when error occurs. -P, --profile TEXT CLI connection profile to use. The default profile is "DEFAULT". -h, -H, --help Show this message and exit.
| Parameter | Data Type | Mandatory | Description |
|---|---|---|---|
| -i / -image-id | String | Yes | ID of the image to be deregistered. |
| -d / --delete-swr-image | Bool | No | Whether to delete a deregistered SWR image. It is disabled by default. |
Debugging an SWR Image on an ECS
ma-cli allows you to debug an SWR image on an ECS to determine whether the image can be used in a ModelArts development workspace.

| Parameter | Data Type | Mandatory | Description |
|---|---|---|---|
| -swr / --swr-path | String | Yes | SWR path to the image to be debugged. |
| -r / --region | String | Yes | Region where the image to be debugged is located. |
| -s / --service | String | No | Service type of the image to be debugged. The value can be NOTEBOOK or MODELBOX. The default value is NOTEBOOK. |
| -a / --arch | String | No | Architecture of the image to be debugged. The value can be X86_64 or AARCH64. The default value is X86_64. |
| -g / --gpu | Bool | No | Whether to use GPUs for debugging. It is disabled by default. |
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