简体   繁体   English

如何以编程方式将容器上传到 Azure 容器注册表

[英]How to programmatically upload a container to Azure Container Registry

Azure has a .NET API that's pretty comprehensive and extensively documented. Azure 有一个非常全面和广泛​​记录的 .NET API There are ways to programmatically accomplish just about anything that you can do in Azure, including all sorts of Docker-related stuff for the Azure Container Service, but one thing I can't find is how to upload a Docker container to an Azure Container Registry on your account.有一些方法可以以编程方式完成您可以在 Azure 中执行的任何操作,包括用于 Azure 容器服务的各种与 Docker 相关的内容,但我找不到的一件事是如何将 Docker 容器上传到 Azure 容器注册表在您的帐户上。 And of course the Azure Container Service is kind of useless without any containers to run.当然,如果没有任何容器运行,Azure 容器服务就毫无用处。

There's plenty of material online about how to do this from a command line, but I can't find any way to do it from the API.网上有很多关于如何从命令行执行此操作的材料,但我找不到任何从 API 执行此操作的方法。 How would I go about pushing a container from within a program?我将如何从程序中推送容器?

This post is intended more like a comment that is readable than a solid answer.这篇文章更像是一个可读的评论,而不是一个可靠的答案。 The task of pushing a container is more complicated than calling a single API.推送容器的任务比调用单个 API 更复杂。 Your code must manage the steps to save the container image to a file, which is a tar archive, then extracting the manifest and layers from the archive and finally uploading those objects to the registry.您的代码必须管理将容器映像保存到一个文件的步骤,该文件是一个 tar 存档,然后从存档中提取清单和层,最后将这些对象上传到注册表。

The Azure Container Registry implements the Docker Registry API. Azure 容器注册表实现了 Docker Registry API。 This means that you will have better results searching for Docker examples.这意味着搜索 Docker 示例将获得更好的结果。

Note: I am not aware of a .NET API, only the REST API and that API is just the blob upload portion.注意:我不知道 .NET API,只有 REST API,而该 API 只是 blob 上传部分。 The rest of the steps you will need to code.您将需要编码的其余步骤。

The first step is to extract the manifest and layers from the container.第一步是从容器中提取清单和层。 Each item is uploaded individually.每个项目都是单独上传的。 docker save and tar simplify this process. docker savetar简化了这个过程。

The process to upload a container is a multi-step process.上传容器的过程是一个多步骤的过程。 The first item to upload is the manifest, then upload each layer.要上传的第一项是清单,然后上传每一层。 Both Docker and Azure call the data "blobs". Docker 和 Azure 都将数据称为“blob”。

This API starts the process:此 API 启动流程:

Blob - Start Upload Blob - 开始上传

Example Docker document which explains the process and the APIs:解释过程和 API 的示例 Docker 文档:

Docker: Pushing An Image Docker:推送镜像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM