Search code examples
speech-to-textazure-cognitive-servicesazure-iot-edge

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


I currently have public preview access for the Azure Cognitive Services for Speech-To-Text as a docker container. This allows the container to be run on an IoT Edge device, rather than accessing the cloud to perform this service. This public preview came with installation instructions that show I can download an existing docker image of one of the containers and run it from a CLI using "docker run".

But I don't want to have to run the docker container manually on my IoT Edge devices. I want it to be automatically deployed to my IoT Edge devices and automatically start running. In order to do this, I believe that it needs to exist as an IoT Edge Module. Is my understanding correct?

So my question is more of an instructional question. Do I need to create my own IoT Edge Module that utilizes this ACS docker container, or is there some other way to automatically deploy it to my IoT Edge Device and have it start running automatically?

I was unable to find any documentation or examples online of deploying an existing docker container to an IoT Edge device. Any guidance would be greatly appreciated!


Solution

  • OK, after much digging, I found a solution. Whatever you do, don't search online for "create iot module from docker container" or anything COMPLETELY MEANINGFUL like that. Instead, I had to search for something very specific to the Azure Cognitive Service's EULA acceptance on the docker run (i.e. I had to search for "iot edge module docker \"eula\""). Note the quotation marks around eula to ensure it is in the search result. I came across this article.

    Using the article's guidance, I will repeat in detail what I did here in case the link ever goes stale.

    1. In VS Code, create a new IoT Edge Solution
    2. In your solution, add a new IoT Edge Module a. When prompted for the type of Module to create, select "Choose Existing Module (Enter Full URL)"
    3. If you look inside your deployment.template.json file, you will now see a new element for "registryCredentials" that got added to your edgeAgent details. Fill out the address, username, and password accordingly.
    4. If you haven't done so yet, create your Cognitive Services resource online to obtain an Endpoint URL and an ApiKey. Take note of these values.
    5. In the deployment.template.json file, under your new module's configuration settings, add the following.

      "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"
            }
            ] 
            }
            }
          }
      

      This will be equivalent to running "docker run" from the command line with parameters like this:

    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. Now "Build and Push your IoT Edge Solution", followed by "Create Deployment for Single Device". On your target IoT Edge device, you should now see the module installed and running via CLI "iotedge list".

    Update: 2020/05/01

    After submitting a request for better documentation from MSFT, they updated their docs site to include information on how to modify the deployment.template.json file to match the docker command line arguments: https://learn.microsoft.com/en-us/azure/iot-edge/how-to-use-create-options