使用镜像注册表和镜像仓库

Snowpark Container Services provides an OCIv2 (https://github.com/opencontainers/distribution-spec/blob/main/spec.md)-compliant image registry service and a storage unit call repository to store images. You can use the following Snowflake CLI commands to manage Snowpark Container Services image registries and repositories:

For more information about Snowpark Container Services image registries and repositories, see Snowpark Container Services: Working with an image registry and repository.

管理镜像注册表

Snowflake CLI lets you perform the following tasks with Snowpark Container Services image repositories:

For common operations, such as listing or dropping, Snowflake CLI uses snow object commands as described in Managing Snowflake objects.

获取用于注册表身份验证的环境令牌

You can use the snow spcs image-registry token command to return the token associated with the specified connection that you can use to authenticate with the registry.

snow spcs image-registry token --connection mytest
+----------------------------------------------------------------------------------------------------------------------+
| key        | value                                                                                                   |
|------------+---------------------------------------------------------------------------------------------------------|
| token      | ****************************************************************************************************    |
|            | ****************************************************************************************************    |
| expires_in | 3600                                                                                                    |
+----------------------------------------------------------------------------------------------------------------------+

You can then use that token to log in to a Docker container by piping it to the docker login command, similar to the following:

snow spcs image-registry token --format=JSON | docker login <org>-<account>.registry.snowflakecomputing.cn -u 0sessiontoken --password-stdin

登录镜像注册表

The snow spcs image-registry login logs you into an image repository with the credentials specified for your connection. Before logging in, you must meet the following prerequisites:

要使用您的账户凭据登录到镜像注册表,请使用以下命令:

snow spcs image-registry login
Login Succeeded

检索镜像注册表的 URL

The snow spcs image-registry url command returns a URL for an image repository. The current role must have READ privileges for the image repository in the account to get the registry URL.

要获取镜像仓库的 URL,请执行以下操作:

snow spcs image-registry url
<orgname-acctname>.registry.snowflakecomputing.cn

管理镜像仓库

Snowflake CLI lets you perform the following tasks with Snowpark Container Services image repositories:

For common operations, such as listing or dropping, Snowflake CLI uses snow object commands as described in Managing Snowflake objects.

创建镜像仓库

The snow spcs image-repository create command creates a new image repository in the current schema.

要创建镜像仓库,请输入类似下面的命令:

snow spcs image-repository create tutorial_repository
+-------------------------------------------+
| key    | value                            |
|--------+----------------------------------|
| status | Statement executed successfully. |
+-------------------------------------------+

根据项目定义创建和部署镜像仓库

You can deploy an image repository to a stage by creating a snowflake.yml project definition file and executing the snow spcs image-repository deploy command.

The following shows a sample snowflake.yml project definition file:

definition_version: 2
entities:
  my_image_repository:
    type: image-repository
    identifier: my_image_repository

下表描述了计算池项目定义的属性。

Image repository project definition properties

PropertyDefinition

type

requiredstring

Must be image-repository.

identifier

optionalstring

实体的 Snowflake 标识符。该值可以采用以下形式:

  • 字符串标识符文本
identifier: my-image-repository

Both unquoted and quoted identifiers are supported. To use quoted identifiers, include the surrounding quotes in the YAML value (for example, "My Image Repository").

  • 对象
identifier:
  name: my-image-repository
  schema: my-schema # optional
  database: my-db # optional

Note

An error occurs if you specify a schema or database and use a fully qualified name in the name property (such as mydb.schema1.my-app).

要创建和部署镜像仓库,请执行以下操作:

  1. 将当前目录更改为包含项目定义文件的目录。

  2. Run a snow spcs image-repository deploy command similar to the following:

    snow spcs image-repository deploy
    +---------------------------------------------------------------------+
    | key    | value                                                      |
    |--------+------------------------------------------------------------|
    | status | Image Repository MY_IMAGE_REPOSITORY successfully created. |
    +---------------------------------------------------------------------+

检索镜像仓库的 URL

The snow spcs image-repository url command gets the URL for an image repository.

要获取 URL,请输入类似下面的命令:

snow spcs image-repository url tutorial_repository
<orgname-acctname>.registry.snowflakecomputing.cn/tutorial_db/data_schema/tutorial_repository

列出镜像仓库中的标签和镜像

The snow spcs image-repository list-images command lets you get the images and tags for an image repository.

To list the images and tags in a repository, enter a command similar to the following, which lists the images in a repository named images in the my_db database:

snow spcs image-repository list-images images --database my_db
+----------------------------+---------------+---------+-------------------------------------------------+-----------------------------------------+
| created_on                 | image_name    | tags    | digest                                          | image_path                              |
|----------------------------+---------------+---------+-------------------------------------------------+-----------------------------------------|
| 2024-10-11 14:23:49-07:00  | echo_service  | latest  | sha256:a8a001fef406fdb3125ce8e8bf9970c35af7084  | my_db/test_schema/images/echo_service:  |
|                            |               |         | fc33b0886d7a8915d3082c781                       | latest                                  |
| 2024-10-14 22:21:14-07:00  | test_counter  | latest  | sha256:8cae96dac29a4a05f54bb5520003f964baf67fc  | my_db/test_schema/images/test_counter:  |
|                            |               |         | 38dcad3d2c85d6c5aa7381174                       | latest                                  |
+----------------------------+---------------+---------+-------------------------------------------------+-----------------------------------------+