Azure ACI Wordpress 模板建立数据库连接时出错

Azure ACI Wordpress Template Error establishing a database connection

你好 Azure 容器专家

我正在尝试配置以下 Azure 容器设置:

我的第一步(为简单起见)是在 Azure 上的单个容器组中创建 2 个容器(没有文件共享)。我创建了以下 Azure 资源管理器模板来创建 ACI

我在下面的博客中使用这里

手臂模板

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
       
    },
    "resources": [
      {
        "name": "test-wordpress-container-group",
        "type": "Microsoft.ContainerInstance/containerGroups",
        "apiVersion": "2018-02-01-preview",
        "location": "[resourceGroup().location]",
        "properties": {
          "containers": [
            {
                "name": "front-end",
                "properties": {
                  "image": "wordpress",
                  "resources": {
                    "requests": {
                      "cpu": 1,
                      "memoryInGb": 1.0
                    }
                  },
                  "ports": [
                    {
                      "port": 80
                    }
                  ],
                  "environmentVariables": [
                      {
                          "name": "WORDPRESS_DB_PASSWORD",
                          "value": "wordpress"
                      },
                      {
                          "name": "WORDPRESS_DB_HOST",
                          "value": "127.0.0.0:3306"
                      }
                  ]
                }
              },
            {
                "name": "back-end",
                "properties": {
                  "image": "mysql:5.7",
                  "resources": {
                    "requests": {
                      "cpu": 1,
                      "memoryInGb": 1.0
                    }
                  },
                  "ports": [
                      {
                          "protocol": "tcp",
                          "port": "3306"
                      }
                  ],
                  "environmentVariables": [
                      {
                          "name": "MYSQL_ROOT_PASSWORD",
                          "value": "mysql"
                      }
                  ]
                }
              }
          ],
          "osType": "Linux",
          "restartPolicy": "OnFailure",
          "ipAddress": {
            "type": "Public",
            "dnsNameLabel": "wordpress-app",
            "ports": [
              {
                "protocol": "tcp",
                "port": 80
              }
            ]
          }
        }
      }
    ],
    "outputs": {
      "containerIPv4Address": {
        "type": "string",
        "value": "[reference(resourceId('Microsoft.ContainerInstance/containerGroups/', 'wordpress-container-group')).ipAddress.ip]"
      }
    }
}

为了执行 ARM 模板,我使用了以下语句:

az group deployment create -n TestDeployment -g rg-WordPress  --template-file "azuredeploy.json"

成功部署后,我访问了 public URL。我希望看到 WordPress 安装页面的地方。但是,我收到以下错误:

Error establishing a database connection

您的 ARM 模板中存在一些错误,例如 WORDPRESS_DB_HOST 的值应该是 "127.0.0.1:3306" 而不是 "127.0.0.0:3306" 并且端口号应该是 "port": 3306 而不是"port": "3306"。此外,图像 wordpress 对我不起作用,相反,使用图像 wordpress:4.9-apache 有效。

示例

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "mysqlPassword": {
            "type": "securestring",
            "defaultValue": "xxxxx",
            "metadata": {
              "description": "Root password password for the MySQL database."
            }
    
          },
          "containerGroupName": {
              "type": "string",
              "defaultValue": "xxxxxx",
              "metadata": {
                  "description": "Name for the container group"
              }          
          },
          "dnsNameLabel": {
            "type": "string",
            "defaultValue": "xxxx",
            "metadata": {
                "description": "DNS Name Label for the container group"
            }
        }
    },
    "resources": [
      {
        "name": "[parameters('containerGroupName')]",
        "type": "Microsoft.ContainerInstance/containerGroups",
        "apiVersion": "2018-02-01-preview",
        "location": "[resourceGroup().location]",
        "properties": {
          "containers": [
            {
                "name": "front-end",
                "properties": {
                  "image": "wordpress:4.9-apache",  
                  "resources": {
                    "requests": {
                      "cpu": 1,
                      "memoryInGb": 1.0
                    }
                  },
                  "ports": [
                    {
                      "port": 80
                    }
                  ],
                  "environmentVariables": [
                      {
                          "name": "WORDPRESS_DB_PASSWORD",
                          "value": "[parameters('mysqlPassword')]"
                      },
                      {
                          "name": "WORDPRESS_DB_HOST",
                          "value": "127.0.0.1:3306"
                      }
                  ]
                }
              },
            {
                "name": "back-end",
                "properties": {
                  "image": "mysql:5.7",
                  "resources": {
                    "requests": {
                      "cpu": 1,
                      "memoryInGb": 1.0
                    }
                  },
                  "ports": [
                      {
                          "protocol": "tcp",
                          "port": 3306
                      }
                  ],
                  "environmentVariables": [
                      {
                          "name": "MYSQL_ROOT_PASSWORD",
                          "value": "[parameters('mysqlPassword')]"
                      }
                  ]
                }
              }
          ],
          "osType": "Linux",
          "restartPolicy": "OnFailure",
          "ipAddress": {
            "type": "Public",
            "dnsNameLabel": "[parameters('dnsNameLabel')]",
            "ports": [
              {
                "protocol": "tcp",
                "port": 80
              }
            ]
          }
        }
      }
    ],
    "outputs": {
      "containerIPv4Address": {
        "type": "string",
        "value": "[reference(resourceId('Microsoft.ContainerInstance/containerGroups/', parameters('containerGroupName'))).ipAddress.ip]"
      }
    }
}

结果