如何使用 REST api 将文件存储卷挂载到 Azure 容器实例

我正在尝试创建 Azure 容器实例并通过 REST API 安装文件存储卷,但收到 400 响应。


我能够创建容器并使其保持运行但是当我添加卷部分时它返回 400 响应(错误请求)而没有进一步解释


这是我发送到 REST 端点的 JSON 负载:


{

  "id": "/subscriptions/111111111/resourceGroups/OraResourceGroup/providers/Microsoft.ContainerInstance/containerGroups/solver",

  "location": "West Europe",

  "name": "solver",

  "properties": {

    "volumes": [

      {

        "azureFile": {

          "shareName": "orafileshare",

          "storageAccountKey": "somekey",

          "storageAccountName": "myaccountname"

        },

        "name": "Volume1"

      }

    ],

    "containers": [

      {

        "name": "solver",

        "properties": {

          "command": [],

          "environmentVariables": [],

          "image": "acraccount/solver:v1",

          "ports": [

            {

              "port": 12345

            }

          ],

          "resources": {

            "requests": {

              "cpu": 1.0,

              "memoryInGB": 1.5

            }

          },

          "volumeMounts": [

            {

              "name": "Volume1",

              "mountPath": "/mountFolder"

            }

          ]

        }

      }

    ],

    "imageRegistryCredentials": [

      {

        "password": "123123123213123",

        "server": "acr.server.io",

        "username": "acrOra"

      }

    ],

    "ipAddress": {

      "ports": [

        {

          "protocol": "TCP",

          "port": 12345

        }

      ],

      "type": "Public"

    },

    "osType": "Linux",

    "restartPolicy": "Always"

  },

  "type": "Microsoft.ContainerInstance/containerGroups"

}

预期结果是 200 或 201 响应,容器应该出现在我的 Azure 门户仪表板上,但实际响应是 400。


杨魅力
浏览 84回答 1
1回答

翻翻过去那场雪

此更正有 2 个问题。我也收到了 400 个错误的请求,但后来更正了它,我能够成功运行它。卷名,不允许大写字母。Change "Volume1" to "volume1"参考错误:{"error":{"code":"InvalidVolumeName","message":"The volume name 'Volume1' is invalid. The volume name must match the regex '[a-z0-9]([-a-z0-9]*[a-z0-9])?' (e.g. 'my-name')."}}Sku 不是有效属性,请将其删除{"error":{"code":"InvalidRequestContent","message":"The request content was invalid and could not be deserialized: 'Could not find member 'sku' on object of type 'ComputeResources'. Path 'properties.containers[0].properties.resources.requests.sku', line 32, position 22.'."}}参考https://learn.microsoft.com/en-us/rest/api/container-instances/containergroups/createorupdate#resourcerequests示例配置{  "id": "/subscriptions/xxxx/resourceGroups/teststoragerest/providers/Microsoft.ContainerInstance/containerGroups/solver",  "location": "West Europe",  "name": "demo1forrahul",  "properties": {    "volumes": [      {        "azureFile": {          "shareName": "testfilestorage",          "storageAccountKey": "xxxx",          "storageAccountName": "xxxxxx"        },        "name": "volume1"      }    ],    "containers": [      {        "name": "demo1forrahul",        "properties": {          "command": [],          "environmentVariables": [],          "image": "nginx",          "ports": [            {              "port": 80            }          ],          "resources": {            "requests": {              "cpu": 1.0,              "memoryInGB": 1.5            }          },          "volumeMounts": [            {              "name": "volume1",              "mountPath": "/testfolder"            }          ]        }      }    ],    "imageRegistryCredentials": [],    "ipAddress": {      "ports": [        {          "protocol": "TCP",          "port": 80        }      ],      "type": "Public"    },    "osType": "Linux",    "restartPolicy": "Always"  },  "type": "Microsoft.ContainerInstance/containerGroups"}
打开App,查看更多内容
随时随地看视频慕课网APP