您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

教程:在用于容器的 Web 应用中创建多容器(预览版)应用Tutorial: Create a multi-container (preview) app in Web App for Containers

备注

多容器处于预览状态。Multi-container is in preview.

用于容器的 Web 应用中可以灵活使用 Docker 映像。Web App for Containers provides a flexible way to use Docker images. 本教程介绍如何使用 WordPress 和 MySQL 创建多容器应用。In this tutorial, you'll learn how to create a multi-container app using WordPress and MySQL. 你将在 Cloud Shell 中完成本教程,但是也可以使用 Azure CLI 命令行工具(2.0.32 或更高版本)在本地运行这些命令。You'll complete this tutorial in Cloud Shell, but you can also run these commands locally with the Azure CLI command-line tool (2.0.32 or later).

在本教程中,你将了解如何执行以下操作:In this tutorial, you learn how to:

  • 转换 Docker Compose 配置以使用用于容器的 Web 应用Convert a Docker Compose configuration to work with Web App for Containers
  • 将多容器应用部署到 AzureDeploy a multi-container app to Azure
  • 添加应用程序设置Add application settings
  • 对容器使用持久性存储Use persistent storage for your containers
  • 连接到 Azure Database for MySQLConnect to Azure Database for MySQL
  • 排查错误Troubleshoot errors

如果还没有 Azure 订阅,可以在开始前创建一个免费帐户If you don't have an Azure subscription, create a free account before you begin.

先决条件Prerequisites

若要完成本教程,需要具有使用 Docker Compose 的经验。To complete this tutorial, you need experience with Docker Compose.

下载示例Download the sample

本教程使用 Docker 中的 compose 文件,但我们将对其进行修改,使之包含 Azure Database for MySQL、持久性存储和 Redis。For this tutorial, you use the compose file from Docker, but you'll modify it to include Azure Database for MySQL, persistent storage, and Redis. 可在 Azure 示例中找到该配置文件。The configuration file can be found at Azure Samples. 有关受支持的配置选项,请参阅 Docker Compose 选项For supported configuration options, see Docker Compose options.

version: '3.3'

services:
   db:
     image: mysql:5.7
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: somewordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     ports:
       - "8000:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
volumes:
    db_data:

在 Cloud Shell 中,创建一个 tutorial 目录,然后切换到该目录。In Cloud Shell, create a tutorial directory and then change to it.

mkdir tutorial

cd tutorial

接下来,运行以下命令将示例应用存储库克隆到 tutorial 目录。Next, run the following command to clone the sample app repository to your tutorial directory. 然后切换到 multicontainerwordpress 目录。Then change to the multicontainerwordpress directory.

git clone https://github.com/Azure-Samples/multicontainerwordpress

cd multicontainerwordpress

创建资源组Create a resource group

资源组是在其中部署和管理 Azure 资源(如 Web 应用、数据库和存储帐户)的逻辑容器。A resource group is a logical container into which Azure resources like web apps, databases, and storage accounts are deployed and managed. 例如,可以选择在使用完之后通过一个简单的步骤删除整个资源组。For example, you can choose to delete the entire resource group in one simple step later.

在 Cloud Shell 中,使用 az group create 命令创建资源组。In Cloud Shell, create a resource group with the az group create command. 下面的示例命令在“美国中南部”位置创建名为 myResourceGroup 的资源组。 The following example creates a resource group named myResourceGroup in the South Central US location. 若要查看标准层中 Linux 上的应用服务支持的所有位置,请运行 az appservice list-locations --sku S1 --linux-workers-enabled 命令。To see all supported locations for App Service on Linux in Standard tier, run the az appservice list-locations --sku S1 --linux-workers-enabled command.

az group create --name myResourceGroup --location "South Central US"

通常在附近的区域中创建资源组和资源。You generally create your resource group and the resources in a region near you.

此命令完成后,JSON 输出会显示资源组属性。When the command finishes, a JSON output shows you the resource group properties.

创建 Azure 应用服务计划Create an Azure App Service plan

在 Cloud Shell 中,使用 az appservice plan create 命令在资源组中创建应用服务计划。In Cloud Shell, create an App Service plan in the resource group with the az appservice plan create command.

以下示例在标准定价层 (--sku S1) 和 Linux 容器 (--is-linux) 中创建名为 myAppServicePlan 的应用服务计划。The following example creates an App Service plan named myAppServicePlan in the Standard pricing tier (--sku S1) and in a Linux container (--is-linux).

az appservice plan create --name myAppServicePlan --resource-group myResourceGroup --sku S1 --is-linux

创建应用服务计划后,Cloud Shell 会显示类似于以下示例的信息。When the App Service plan has been created, Cloud Shell shows information similar to the following example:

{
  "adminSiteName": null,
  "appServicePlanName": "myAppServicePlan",
  "geoRegion": "South Central US",
  "hostingEnvironmentProfile": null,
  "id": "/subscriptions/0000-0000/resourceGroups/myResourceGroup/providers/Microsoft.Web/serverfarms/myAppServicePlan",
  "kind": "linux",
  "location": "South Central US",
  "maximumNumberOfWorkers": 1,
  "name": "myAppServicePlan",
  < JSON data removed for brevity. >
  "targetWorkerSizeId": 0,
  "type": "Microsoft.Web/serverfarms",
  "workerTierName": null
}

使用 WordPress 和 MySQL 容器的 Docker ComposeDocker Compose with WordPress and MySQL containers

创建 Docker Compose 应用Create a Docker Compose app

在 Cloud Shell 中,使用 az webapp create 命令在 myAppServicePlan 应用服务计划中创建一个多容器 Web 应用In your Cloud Shell, create a multi-container web app in the myAppServicePlan App Service plan with the az webapp create command. 不要忘记将 <app-name> 替换为唯一的应用名称 。Don't forget to replace <app-name> with a unique app name.

az webapp create --resource-group myResourceGroup --plan myAppServicePlan --name <app-name> --multicontainer-config-type compose --multicontainer-config-file docker-compose-wordpress.yml

创建 Web 应用后,Cloud Shell 会显示类似于以下示例的输出:When the web app has been created, Cloud Shell shows output similar to the following example:

{
  "additionalProperties": {},
  "availabilityState": "Normal",
  "clientAffinityEnabled": true,
  "clientCertEnabled": false,
  "cloningInfo": null,
  "containerSize": 0,
  "dailyMemoryTimeQuota": 0,
  "defaultHostName": "<app-name>.azurewebsites.net",
  "enabled": true,
  < JSON data removed for brevity. >
}

浏览到应用Browse to the app

浏览到所部署的应用 (http://<app-name>.azurewebsites.net)。Browse to the deployed app at (http://<app-name>.azurewebsites.net). 该应用可能需要几分钟时间才能完成加载。The app may take a few minutes to load. 如果收到错误,请在几分钟后刷新浏览器。If you receive an error, allow a few more minutes then refresh the browser. 如果遇到问题并想要进行故障排除,请查看容器日志If you're having trouble and would like to troubleshoot, review container logs.

用于容器的 Web 应用中的示例多容器应用

祝贺你,现已在用于容器的 Web 应用中创建了多容器应用。Congratulations, you've created a multi-container app in Web App for Containers. 接下来,请将应用配置为使用 Azure Database for MySQL。Next you'll configure your app to use Azure Database for MySQL. 暂时不要安装 WordPress。Don't install WordPress at this time.

连接到生产数据库Connect to production database

不建议在生产环境中使用数据库容器。It's not recommended to use database containers in a production environment. 本地容器不可缩放。The local containers aren't scalable. 应改用可缩放的 Azure Database for MySQL。Instead, you'll use Azure Database for MySQL which can be scaled.

创建 Azure Database for MySQL 服务器Create an Azure Database for MySQL server

使用 az mysql server create 命令创建 Azure Database for MySQL 服务器。Create an Azure Database for MySQL server with the az mysql server create command.

在以下命令中,请将 <mysql-server-name> 占位符替换为你的 MySQL 服务器名称(有效字符是 a-z0-9-) 。In the following command, substitute your MySQL server name where you see the <mysql-server-name> placeholder (valid characters are a-z, 0-9, and -). 此名称是 MySQL 服务器主机名 (<mysql-server-name>.database.windows.net) 的一部分,必须全局唯一。This name is part of the MySQL server's hostname (<mysql-server-name>.database.windows.net), it needs to be globally unique.

az mysql server create --resource-group myResourceGroup --name <mysql-server-name>  --location "South Central US" --admin-user adminuser --admin-password My5up3rStr0ngPaSw0rd! --sku-name B_Gen4_1 --version 5.7

创建服务器可能需要几分钟才能完成。Creating the server may take a few minutes to complete. 创建 MySQL 服务器后,Cloud Shell 会显示类似于以下示例的信息:When the MySQL server is created, Cloud Shell shows information similar to the following example:

{
  "administratorLogin": "adminuser",
  "administratorLoginPassword": null,
  "fullyQualifiedDomainName": "<mysql-server-name>.database.windows.net",
  "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.DBforMySQL/servers/<mysql-server-name>",
  "location": "southcentralus",
  "name": "<mysql-server-name>",
  "resourceGroup": "myResourceGroup",
  ...
}

配置服务器防火墙Configure server firewall

使用 az mysql server firewall-rule create 命令创建 MySQL 服务器的防火墙规则,以便建立客户端连接。Create a firewall rule for your MySQL server to allow client connections by using the az mysql server firewall-rule create command. 若同时将起始 IP 和结束 IP 设置为 0.0.0.0,防火墙将仅对其他 Azure 资源开启。When both starting IP and end IP are set to 0.0.0.0, the firewall is only opened for other Azure resources.

az mysql server firewall-rule create --name allAzureIPs --server <mysql-server-name> --resource-group myResourceGroup --start-ip-address 0.0.0.0 --end-ip-address 0.0.0.0

提示

你甚至可以让防火墙规则更严格,即只使用应用所使用的出站 IP 地址You can be even more restrictive in your firewall rule by using only the outbound IP addresses your app uses.

创建 WordPress 数据库Create the WordPress database

az mysql db create --resource-group myResourceGroup --server-name <mysql-server-name> --name wordpress

创建数据库后,Cloud Shell 会显示类似于以下示例的信息:When the database has been created, Cloud Shell shows information similar to the following example:

{
  "additionalProperties": {},
  "charset": "latin1",
  "collation": "latin1_swedish_ci",
  "id": "/subscriptions/12db1644-4b12-4cab-ba54-8ba2f2822c1f/resourceGroups/myResourceGroup/providers/Microsoft.DBforMySQL/servers/<mysql-server-name>/databases/wordpress",
  "name": "wordpress",
  "resourceGroup": "myResourceGroup",
  "type": "Microsoft.DBforMySQL/servers/databases"
}

在 WordPress 中配置数据库变量Configure database variables in WordPress

若要将 WordPress 应用连接到这个新的 MySQL 服务器,请配置几个特定于 WordPress 的环境变量,包括 MYSQL_SSL_CA 定义的 SSL CA 路径。To connect the WordPress app to this new MySQL server, you'll configure a few WordPress-specific environment variables, including the SSL CA path defined by MYSQL_SSL_CA. 以下自定义映像中提供了来自 DigiCertBaltimore 网络信任根证书The Baltimore CyberTrust Root from DigiCert is provided in the custom image below.

若要进行这些更改,请在 Cloud Shell 中使用 az webapp config appsettings set 命令。To make these changes, use the az webapp config appsettings set command in Cloud Shell. 应用设置区分大小写,用空格分开。App settings are case-sensitive and space-separated.

az webapp config appsettings set --resource-group myResourceGroup --name <app-name> --settings WORDPRESS_DB_HOST="<mysql-server-name>.mysql.database.azure.com" WORDPRESS_DB_USER="adminuser@<mysql-server-name>" WORDPRESS_DB_PASSWORD="My5up3rStr0ngPaSw0rd!" WORDPRESS_DB_NAME="wordpress" MYSQL_SSL_CA="BaltimoreCyberTrustroot.crt.pem"

创建应用设置后,Cloud Shell 会显示类似于以下示例的信息。When the app setting has been created, Cloud Shell shows information similar to the following example:

[
  {
    "name": "WORDPRESS_DB_HOST",
    "slotSetting": false,
    "value": "<mysql-server-name>.mysql.database.azure.com"
  },
  {
    "name": "WORDPRESS_DB_USER",
    "slotSetting": false,
    "value": "adminuser@<mysql-server-name>"
  },
  {
    "name": "WORDPRESS_DB_NAME",
    "slotSetting": false,
    "value": "wordpress"
  },
  {
    "name": "WORDPRESS_DB_PASSWORD",
    "slotSetting": false,
    "value": "My5up3rStr0ngPaSw0rd!"
  },
  {
    "name": "MYSQL_SSL_CA",
    "slotSetting": false,
    "value": "BaltimoreCyberTrustroot.crt.pem"
  }
]

有关环境变量的详细信息,请参阅配置环境变量For more information on environment variables, see Configure environment variables.

对 MySQL SSL 和其他配置使用自定义映像Use a custom image for MySQL SSL and other configurations

默认情况下,SSL 由 Azure Database for MySQL 使用。By default, SSL is used by Azure Database for MySQL. WordPress 需要附加的配置才能将 SSL 和 MySQL 配合使用。WordPress requires additional configuration to use SSL with MySQL. WordPress“官方映像”不提供附加的配置,但出于方便,已准备了一个自定义映像The WordPress 'official image' doesn't provide the additional configuration, but a custom image has been prepared for your convenience. 在实践中,请将所需的更改添加到自己的映像。In practice, you would add desired changes to your own image.

自定义映像基于 Docker 中心的 WordPress 的“官方映像”。The custom image is based on the 'official image' of WordPress from Docker Hub. 适用于 Azure Database for MySQL 的此自定义映像中已做出以下更改:The following changes have been made in this custom image for Azure Database for MySQL:

为 Redis 做出了以下更改(在稍后的部分中使用):The following changes have been made for Redis (to be used in a later section):

若要使用自定义映像,请更新 docker-compose-wordpress.yml 文件。To use the custom image, you'll update your docker-compose-wordpress.yml file. 在 Cloud Shell 中,键入 nano docker-compose-wordpress.yml 打开 nano 文本编辑器。In Cloud Shell, type nano docker-compose-wordpress.yml to open the nano text editor. 更改 image: wordpress 以使用 image: microsoft/multicontainerwordpressChange the image: wordpress to use image: microsoft/multicontainerwordpress. 不再需要数据库容器。You no longer need the database container. 从配置文件中删除 dbenvironmentdepends_onvolumes 节。Remove the db, environment, depends_on, and volumes section from the configuration file. 文件应如以下代码所示:Your file should look like the following code:

version: '3.3'

services:
   wordpress:
     image: microsoft/multicontainerwordpress
     ports:
       - "8000:80"
     restart: always

保存更改并退出 nano。Save your changes and exit nano. 使用命令 ^O 来保存,使用 ^X 来退出。Use the command ^O to save and ^X to exit.

使用新配置更新应用Update app with new configuration

在 Cloud Shell 中,使用 az webapp config container set 命令重新配置多容器 Web 应用In Cloud Shell, reconfigure your multi-container web app with the az webapp config container set command. 不要忘记将 <app-name> 替换为前面创建的 Web 应用的名称 。Don't forget to replace <app-name> with the name of the web app you created earlier.

az webapp config container set --resource-group myResourceGroup --name <app-name> --multicontainer-config-type compose --multicontainer-config-file docker-compose-wordpress.yml

重新配置应用后,Cloud Shell 会显示类似于以下示例的信息:When the app has been reconfigured, Cloud Shell shows information similar to the following example:

[
  {
    "name": "DOCKER_CUSTOM_IMAGE_NAME",
    "value": "COMPOSE|dmVyc2lvbjogJzMuMycKCnNlcnZpY2VzOgogICB3b3JkcHJlc3M6CiAgICAgaW1hZ2U6IG1zYW5nYXB1L3dvcmRwcmVzcwogICAgIHBvcnRzOgogICAgICAgLSAiODAwMDo4MCIKICAgICByZXN0YXJ0OiBhbHdheXM="
  }
]

浏览到应用Browse to the app

浏览到所部署的应用 (http://<app-name>.azurewebsites.net)。Browse to the deployed app at (http://<app-name>.azurewebsites.net). 应用正在使用 Azure Database for MySQL。The app is now using Azure Database for MySQL.

用于容器的 Web 应用中的示例多容器应用

添加持久性存储Add persistent storage

多容器应用正在用于容器的 Web 应用中运行。Your multi-container is now running in Web App for Containers. 但是,如果现在安装 WordPress 并稍后重启应用,则会发现 WordPress 安装已消失。However, if you install WordPress now and restart your app later, you'll find that your WordPress installation is gone. 之所以发生这种情况,是因为 Docker Compose 配置当前指向容器中的存储位置。This happens because your Docker Compose configuration currently points to a storage location inside your container. 重启应用后,在容器中安装的文件不会保留。The files installed into your container don't persist beyond app restart. 在本部分,我们将向 WordPress 容器添加持久性存储In this section, you'll add persistent storage to your WordPress container.

配置环境变量Configure environment variables

若要使用持久性存储,请在应用服务中启用此设置。To use persistent storage, you'll enable this setting within App Service. 若要进行此项更改,请在 Cloud Shell 中使用 az webapp config appsettings set 命令。To make this change, use the az webapp config appsettings set command in Cloud Shell. 应用设置区分大小写,用空格分开。App settings are case-sensitive and space-separated.

az webapp config appsettings set --resource-group myResourceGroup --name <app-name> --settings WEBSITES_ENABLE_APP_SERVICE_STORAGE=TRUE

创建应用设置后,Cloud Shell 会显示类似于以下示例的信息。When the app setting has been created, Cloud Shell shows information similar to the following example:

[
  < JSON data removed for brevity. >
  {
    "name": "WORDPRESS_DB_NAME",
    "slotSetting": false,
    "value": "wordpress"
  },
  {
    "name": "WEBSITES_ENABLE_APP_SERVICE_STORAGE",
    "slotSetting": false,
    "value": "TRUE"
  }
]

修改配置文件Modify configuration file

在 Cloud Shell 中,键入 nano docker-compose-wordpress.yml 以打开 nano 文本编辑器。In the Cloud Shell, type nano docker-compose-wordpress.yml to open the nano text editor.

volumes 选项将文件系统映射到容器中的某个目录。The volumes option maps the file system to a directory within the container. ${WEBAPP_STORAGE_HOME} 是应用服务中已映射到应用持续性存储的环境变量。${WEBAPP_STORAGE_HOME} is an environment variable in App Service that is mapped to persistent storage for your app. 将在 volumes 选项中使用此环境变量,以便将 WordPress 文件安装到持久性存储,而不是安装到容器。You'll use this environment variable in the volumes option so that the WordPress files are installed into persistent storage instead of the container. 对文件做出以下修改:Make the following modifications to the file:

如以下代码所示,在 wordpress 节中添加 volumes 选项:In the wordpress section, add a volumes option so it looks like the following code:

version: '3.3'

services:
   wordpress:
     image: microsoft/multicontainerwordpress
     volumes:
      - ${WEBAPP_STORAGE_HOME}/site/wwwroot:/var/www/html
     ports:
       - "8000:80"
     restart: always

使用新配置更新应用Update app with new configuration

在 Cloud Shell 中,使用 az webapp config container set 命令重新配置多容器 Web 应用In Cloud Shell, reconfigure your multi-container web app with the az webapp config container set command. 不要忘记将 <app-name> 替换为唯一的应用名称 。Don't forget to replace <app-name> with a unique app name.

az webapp config container set --resource-group myResourceGroup --name <app-name> --multicontainer-config-type compose --multicontainer-config-file docker-compose-wordpress.yml

该命令运行后,会显示类似于以下示例的输出:After your command runs, it shows output similar to the following example:

[
  {
    "name": "WEBSITES_ENABLE_APP_SERVICE_STORAGE",
    "slotSetting": false,
    "value": "TRUE"
  },
  {
    "name": "DOCKER_CUSTOM_IMAGE_NAME",
    "value": "COMPOSE|dmVyc2lvbjogJzMuMycKCnNlcnZpY2VzOgogICBteXNxbDoKICAgICBpbWFnZTogbXlzcWw6NS43CiAgICAgdm9sdW1lczoKICAgICAgIC0gZGJfZGF0YTovdmFyL2xpYi9teXNxbAogICAgIHJlc3RhcnQ6IGFsd2F5cwogICAgIGVudmlyb25tZW50OgogICAgICAgTVlTUUxfUk9PVF9QQVNTV09SRDogZXhhbXBsZXBhc3MKCiAgIHdvcmRwcmVzczoKICAgICBkZXBlbmRzX29uOgogICAgICAgLSBteXNxbAogICAgIGltYWdlOiB3b3JkcHJlc3M6bGF0ZXN0CiAgICAgcG9ydHM6CiAgICAgICAtICI4MDAwOjgwIgogICAgIHJlc3RhcnQ6IGFsd2F5cwogICAgIGVudmlyb25tZW50OgogICAgICAgV09SRFBSRVNTX0RCX1BBU1NXT1JEOiBleGFtcGxlcGFzcwp2b2x1bWVzOgogICAgZGJfZGF0YTo="
  }
]

浏览到应用Browse to the app

浏览到所部署的应用 (http://<app-name>.azurewebsites.net)。Browse to the deployed app at (http://<app-name>.azurewebsites.net).

WordPress 容器正在使用 Azure Database for MySQL 和持久性存储。The WordPress container is now using Azure Database for MySQL and persistent storage.

添加 Redis 容器Add Redis container

WordPress“官方映像”不包含 Redis 的依赖项。The WordPress 'official image' does not include the dependencies for Redis. 自定义映像中准备好这些依赖项和所需的附加配置,以便用户能够配合 WordPress 使用 Redis。These dependencies and additional configuration needed to use Redis with WordPress have been prepared for you in this custom image. 在实践中,请将所需的更改添加到自己的映像。In practice, you would add desired changes to your own image.

自定义映像基于 Docker 中心的 WordPress 的“官方映像”。The custom image is based on the 'official image' of WordPress from Docker Hub. 适用于 Redis 的此自定义映像中已做出以下更改:The following changes have been made in this custom image for Redis:

如以下示例所示,将 Redis 容器添加到配置文件的底部:Add the redis container to the bottom of the configuration file so it looks like the following example:

version: '3.3'

services:
   wordpress:
     image: microsoft/multicontainerwordpress
     ports:
       - "8000:80"
     restart: always

   redis:
     image: redis:3-alpine
     restart: always

配置环境变量Configure environment variables

若要使用 Redis,请在应用服务中启用 WP_REDIS_HOST 设置。To use Redis, you'll enable this setting, WP_REDIS_HOST, within App Service. WordPress 在与 Redis 主机通信时必须使用此设置。 This is a required setting for WordPress to communicate with the Redis host. 若要进行此项更改,请在 Cloud Shell 中使用 az webapp config appsettings set 命令。To make this change, use the az webapp config appsettings set command in Cloud Shell. 应用设置区分大小写,用空格分开。App settings are case-sensitive and space-separated.

az webapp config appsettings set --resource-group myResourceGroup --name <app-name> --settings WP_REDIS_HOST="redis"

创建应用设置后,Cloud Shell 会显示类似于以下示例的信息。When the app setting has been created, Cloud Shell shows information similar to the following example:

[
  < JSON data removed for brevity. >
  {
    "name": "WORDPRESS_DB_USER",
    "slotSetting": false,
    "value": "adminuser@<mysql-server-name>"
  },
  {
    "name": "WP_REDIS_HOST",
    "slotSetting": false,
    "value": "redis"
  }
]

使用新配置更新应用Update app with new configuration

在 Cloud Shell 中,使用 az webapp config container set 命令重新配置多容器 Web 应用In Cloud Shell, reconfigure your multi-container web app with the az webapp config container set command. 不要忘记将 <app-name> 替换为唯一的应用名称 。Don't forget to replace <app-name> with a unique app name.

az webapp config container set --resource-group myResourceGroup --name <app-name> --multicontainer-config-type compose --multicontainer-config-file compose-wordpress.yml

该命令运行后,会显示类似于以下示例的输出:After your command runs, it shows output similar to the following example:

[
  {
    "name": "DOCKER_CUSTOM_IMAGE_NAME",
    "value": "COMPOSE|dmVyc2lvbjogJzMuMycKCnNlcnZpY2VzOgogICBteXNxbDoKICAgICBpbWFnZTogbXlzcWw6NS43CiAgICAgdm9sdW1lczoKICAgICAgIC0gZGJfZGF0YTovdmFyL2xpYi9teXNxbAogICAgIHJlc3RhcnQ6IGFsd2F5cwogICAgIGVudmlyb25tZW50OgogICAgICAgTVlTUUxfUk9PVF9QQVNTV09SRDogZXhhbXBsZXBhc3MKCiAgIHdvcmRwcmVzczoKICAgICBkZXBlbmRzX29uOgogICAgICAgLSBteXNxbAogICAgIGltYWdlOiB3b3JkcHJlc3M6bGF0ZXN0CiAgICAgcG9ydHM6CiAgICAgICAtICI4MDAwOjgwIgogICAgIHJlc3RhcnQ6IGFsd2F5cwogICAgIGVudmlyb25tZW50OgogICAgICAgV09SRFBSRVNTX0RCX1BBU1NXT1JEOiBleGFtcGxlcGFzcwp2b2x1bWVzOgogICAgZGJfZGF0YTo="
  }
]

浏览到应用Browse to the app

浏览到所部署的应用 (http://<app-name>.azurewebsites.net)。Browse to the deployed app at (http://<app-name>.azurewebsites.net).

完成上述步骤并安装 WordPress。Complete the steps and install WordPress.

将 WordPress 连接到 RedisConnect WordPress to Redis

以管理员身份登录到 WordPress。在左侧导航栏中选择“插件”,然后选择“安装插件”。 Sign in to WordPress admin. In the left navigation, select Plugins, and then select Installed Plugins.

选择 WordPress 插件

此处显示了所有插件Show all plugins here

在插件页中,找到“Redis 对象缓存”并单击“激活”。 In the plugins page, find Redis Object Cache and click Activate.

激活 Redis

单击“设置” 。Click on Settings.

单击“设置”

单击“启用对象缓存”按钮。 Click the Enable Object Cache button.

单击“启用对象缓存”按钮

WordPress 将连接到 Redis 服务器。WordPress connects to the Redis server. 同一页面上会显示连接状态The connection status appears on the same page.

WordPress 将连接到 Redis 服务器。

祝贺你,现已将 WordPress 连接到 Redis。Congratulations, you've connected WordPress to Redis. 生产就绪的应用正在使用 Azure Database for MySQL、持久性存储和 RedisThe production-ready app is now using Azure Database for MySQL, persistent storage, and Redis. 现在可以扩展应用服务计划以包含多个实例。You can now scale out your App Service Plan to multiple instances.

查找 Docker 容器日志Find Docker Container logs

如果使用多个容器时遇到问题,可以通过浏览到 https://<app-name>.scm.azurewebsites.net/api/logs/docker 来访问容器日志。If you run into issues using multiple containers, you can access the container logs by browsing to: https://<app-name>.scm.azurewebsites.net/api/logs/docker.

将会看到类似于以下示例的输出:You'll see output similar to the following example:

[
   {
      "machineName":"RD00XYZYZE567A",
      "lastUpdated":"2018-05-10T04:11:45Z",
      "size":25125,
      "href":"https://<app-name>.scm.azurewebsites.net/api/vfs/LogFiles/2018_05_10_RD00XYZYZE567A_docker.log",
      "path":"/home/LogFiles/2018_05_10_RD00XYZYZE567A_docker.log"
   }
]

查看每个容器的日志,以及父进程的附加日志。You see a log for each container and an additional log for the parent process. 将相应的 href 值复制到浏览器以查看日志。Copy the respective href value into the browser to view the log.

清理部署Clean up deployment

运行示例脚本后,可以使用以下命令删除资源组以及与其关联的所有资源。After the sample script has been run, the following command can be used to remove the resource group and all resources associated with it.

az group delete --name myResourceGroup

后续步骤Next steps

在本教程中,你了解了如何执行以下操作:In this tutorial, you learned how to:

  • 转换 Docker Compose 配置以使用用于容器的 Web 应用Convert a Docker Compose configuration to work with Web App for Containers
  • 将多容器应用部署到 AzureDeploy a multi-container app to Azure
  • 添加应用程序设置Add application settings
  • 对容器使用持久性存储Use persistent storage for your containers
  • 连接到 Azure Database for MySQLConnect to Azure Database for MySQL
  • 排查错误Troubleshoot errors

继续学习下一篇教程,了解如何将自定义 DNS 名称映射到应用。Advance to the next tutorial to learn how to map a custom DNS name to your app.

或者,查看其他资源:Or, check out other resources: