如何从 Azure 认知服务为现有 docker 容器创建 IoT Edge 模块?

How do I create an IoT Edge Module for an existing docker container from Azure Cognitive Services?

我目前有 public Azure Cognitive Services for Speech-To-Text 作为 docker 容器的预览权限。这允许容器在 IoT Edge 设备上 运行,而不是访问云来执行此服务。此 public 预览附带 installation instructions,表明我可以使用 "docker run" 从 CLI 下载其中一个容器的现有 docker 图像和 运行 它。

但我不想在我的 IoT Edge 设备上手动 运行 docker 容器。我希望它自动部署到我的 IoT Edge 设备并自动启动 运行ning。为了做到这一点,我认为它需要作为物联网边缘模块存在。我的理解正确吗?

所以我的问题更像是一个指导性问题。我是否需要创建自己的 IoT Edge 模块来利用此 ACS docker 容器,或者是否有其他方法可以将其自动部署到我的 IoT Edge 设备并让它自动启动 运行ning?

我无法在线找到有关将现有 docker 容器部署到 IoT Edge 设备的任何文档或示例。任何指导将不胜感激!

好的,经过大量挖掘,我找到了解决方案。无论您做什么,都不要在线搜索 "create iot module from docker container" 或任何类似的完全有意义的内容。相反,我必须在 docker 运行 上搜索与 Azure 认知服务的 EULA 接受度非常具体的内容(即我必须搜索 "iot edge module docker \"eula\"")。请注意 eula 周围的引号以确保它在搜索结果中。我遇到了 this article.

根据文章的指导,我将详细重复我在这里所做的,以防 link 过时。

  1. 在 VS Code 中,创建一个新的 IoT Edge 解决方案
  2. 在您的解决方案中,添加一个新的 IoT Edge 模块 一种。当提示输入要创建的模块类型时,select "Choose Existing Module (Enter Full URL)"
  3. 如果您查看 deployment.template.json 文件,您现在将看到 "registryCredentials" 的一个新元素已添加到您的 edgeAgent 详细信息中。相应地填写地址、用户名和密码。
  4. 如果您还没有这样做,请在线创建认知服务资源以获取端点 URL 和 ApiKey。记下这些值。
  5. 在 deployment.template.json 文件中,在新模块的配置设置下,添加以下内容。

    "settings": {
      "image": "containerpreview.azurecr.io/microsoft/cognitive-services-speech-to-text:latest",
      "createOptions": 
      {                       
        "Cmd": [
            "Eula=accept",
          "Billing={enter-your-EndpointURL}",
            "ApiKey={enter-your-ApiKey}"
        ],
        "HostConfig": {
          "PortBindings": {
          "5000/tcp": [
          {
            "HostPort": "5000"
          }
          ] 
          }
          }
        }
    

    这将等同于命令行中的 运行ning "docker run",参数如下:

docker run --rm -it -p 5000:5000 --memory 4g --cpus 1 \ containerpreview.azurecr.io/microsoft/cognitive-services-recognize-text \ Eula=accept \ Billing={BILLING_ENDPOINT_URI} \ ApiKey={BILLING_KEY}

  1. 现在 "Build and Push your IoT Edge Solution",然后是 "Create Deployment for Single Device"。在您的目标 IoT Edge 设备上,您现在应该看到模块已安装并通过 CLI 运行ning "iotedge list"。

更新:2020/05/01

在向 MSFT 提交更好的文档请求后,他们更新了文档站点以包含有关如何修改 deployment.template.json 文件以匹配 docker 命令行参数的信息:https://docs.microsoft.com/en-us/azure/iot-edge/how-to-use-create-options

这是上面link的精华(https://docs.microsoft.com/en-us/azure/iot-edge/how-to-use-create-options):

Once you have the module working the way you want it (ie: in a docker container), run docker inspect . This command outputs the module details in JSON format. Find the parameters that you configured, and copy the JSON.