如何使用Azure节点sdk创建具有Azure专用ACR映像的容器

时间:2018-06-26 21:36:12

标签: node.js azure azure-container-service azure-container-registry azure-node-sdk

我有以下一段代码试图使用Azure节点sdk创建具有私有ACR映像的Azure容器实例。

            let container = new client.models.Container();
            let acrcredentials = new client.models.ImageRegistryCredential();
            acrcredentials.server = '<acrreponame>.azurecr.io';
            acrcredentials.username = 'username';
            acrcredentials.password = 'password';
            acrcredentials.password = 'password';
            console.log('Launching a container for client', client);

            container.name = 'testcontainer';
            container.environmentVariables = [
                {
                    name: 'SOME_ENV_VAR',
                    value: 'test'
                }
            ];
            container.image = '<acrreponame>.azurecr.io/<image>:<tag>';
            container.ports = [{port: 80}];
            container.resources = {
                requests: {
                    cpu: 1,
                    memoryInGB: 1
                }
            };
            container.imageRegistryCredentials = acrcredentials;
            console.log('Provisioning a container', container);

            client.containerGroups.createOrUpdate(group, containerGroup,
                {
                    containers: [container],
                    osType: 'linux',
                    location: 'eastus',
                    restartPolicy: 'never'
                }
            ).then((r) => {
                console.log('Launched:', r);
            }).catch((r) => {
                console.log('Finished up with error', r);
            });

它给了我下面的错误:

  code: 'InaccessibleImage',
  body: 
   { code: 'InaccessibleImage',
     message: 'The image \'<acrreponame>.azurecr.io/<image>:<tag>\' in container group \'testgroup\' is not accessible. Please check the image and registry credential.' } 
   }

1 个答案:

答案 0 :(得分:1)

您要创建容器组,因此需要在imageRegistryCredentials方法中设置createOrUpdate。容器没有imageRegistryCredentials属性。

删除无效的container.imageRegistryCredentials = acrcredentials;

然后将imageRegistryCredentials:[acrcredentials],添加到createOrUpdate

{
      containers: [container],
      imageRegistryCredentials:[acrcredentials],
      osType: 'linux',
      location: 'eastus',
      restartPolicy: 'never'
}