更新时间:2024-04-30 GMT+08:00

在ModelArts Notebook中进行镜像构建

使用ma-cli image build命令基于指定的Dockerfile进行镜像构建,仅支持在ModelArts Notebook里使用该命令。

$ 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.
表1 参数说明

参数名

参数类型

是否必选

参数说明

FILE_PATH

String

Dockerfile文件所在的路径。

-t / --target

String

表示构建生成的tar包保存在本地的路径,默认是当前文件夹目录。

-swr / --swr-path

String

SWR镜像名称,遵循organization/image_name:tag格式,针对于构建保存tar包场景可以省略。

--context

String

Dockerfile构建时的上下文信息路径,主要用于数据拷贝。

-arg / --build-arg

String

指定构建参数,多个构建参数可以使用--build-arg VERSION=18.04 --build-arg ARCH=X86_64

-obs / --obs-path

String

将生成的tar包自动上传到OBS中。

-f / --force

Bool

是否强制覆盖已存在的SWR镜像,默认不覆盖。

示例

在ModelArts Notebook里进行镜像构建。

ma-cli image build .ma/customize_from_ubuntu_18.04_to_modelarts/Dockerfile -swr notebook_test/my_image:0.0.1

其中“.ma/customize_from_ubuntu_18.04_to_modelarts/Dockerfile”为Dockerfile文件所在路径,“notebook_test/my_image:0.0.1”为构建的新镜像的SWR路径。