Linux 上的 Azure 应用服务常见问题解答Azure App Service on Linux FAQ

随着 Linux 应用服务的发布,我们正在努力添加功能和改进我们的平台。With the release of App Service on Linux, we're working on adding features and making improvements to our platform. 本文提供客户最近提出的问题的解答。This article provides answers to questions that our customers have been asking us recently.

如果你有问题,请对本文发表评论。If you have a question, comment on this article.

内置映像Built-in images

我想对平台提供的内置 Docker 容器进行分叉。在哪里可以找到这些文件?I want to fork the built-in Docker containers that the platform provides. Where can I find those files?

可以在 GitHub 上找到所有 Docker 文件。You can find all Docker files on GitHub. 可以在 Docker Hub 上找到所有 Docker 容器。You can find all Docker containers on Docker Hub.

配置运行时堆栈时,“启动文件”部分的所需值是什么?What are the expected values for the Startup File section when I configure the runtime stack?

堆栈Stack 预期值Expected Value
Java SEJava SE 用于启动 JAR 应用的命令(例如 java -jar /home/site/wwwroot/app.jar --server.port=80the command to start your JAR app (for example, java -jar /home/site/wwwroot/app.jar --server.port=80)
TomcatTomcat 用于执行任何所需配置的脚本的位置(例如 /home/site/deployments/tools/startup_script.shthe location of a script to perform any necessary configurations (for example, /home/site/deployments/tools/startup_script.sh)
Node.jsNode.js PM2 配置文件或脚本文件the PM2 configuration file or your script file
.NET Core.NET Core 编译后的 DLL 名称为 dotnet <myapp>.dllthe compiled DLL name as dotnet <myapp>.dll
RubyRuby 要用于初始化你的应用的 Ruby 脚本the Ruby script that you want to initialize your app with

这些命令或脚本会在内置 Docker 容器启动之后但在应用程序代码启动之前执行。These commands or scripts are executed after the built-in Docker container is started, but before your application code is started.

管理Management

在 Azure 门户中按下“重启”按钮时,会发生什么情况?What happens when I press the restart button in the Azure portal?

此操作等同于 Docker 重启。This action is the same as a Docker restart.

可以使用安全外壳 (SSH) 连接到应用容器虚拟机 (VM) 吗?Can I use Secure Shell (SSH) to connect to the app container virtual machine (VM)?

是的,可以通过源代码管理 (SCM) 站点实现此操作。Yes, you can do that through the source control management (SCM) site.

备注

还可以使用 SSH、SFTP 或 Visual Studio Code(用于实时调试 Node.js 应用)直接从本地开发计算机连接到应用容器。You can also connect to the app container directly from your local development machine using SSH, SFTP, or Visual Studio Code (for live debugging Node.js apps). 有关详细信息,请参阅远程调试和通过 SSH 登录到 Linux 上的应用服务For more information, see Remote debugging and SSH in App Service on Linux.

如何通过 SDK 或 Azure 资源管理器模板创建 Linux 应用服务计划?How can I create a Linux App Service plan through an SDK or an Azure Resource Manager template?

应将应用服务的“保留”字段设置为“true”。Set the reserved field of the app service to true.

持续集成和持续部署Continuous integration and deployment

更新 Docker Hub 上的映像后,我的 Web 应用仍使用旧的 Docker 容器映像。是否支持对自定义容器的持续集成和部署?My web app still uses an old Docker container image after I've updated the image on Docker Hub. Do you support continuous integration and deployment of custom containers?

支持,用于为 Azure 容器注册表或 DockerHub 设置持续集成/部署。Yes, to set up continuous integration/deployment for Azure Container Registry or DockerHub. 对于专用注册表,可以通过先停止然后启动 Web 应用来刷新容器。For private registries, you can refresh the container by stopping and then starting your web app. 或者,可以更改或添加虚拟应用程序设置,从而强制刷新容器。Or you can change or add a dummy application setting to force a refresh of your container.

是否支持过渡环境?Do you support staging environments?

是的。Yes.

是否可以使用 WebDeploy/MSDeploy 来部署 Web 应用?Can I use WebDeploy/MSDeploy to deploy my web app?

可以,需要将名为 WEBSITE_WEBDEPLOY_USE_SCM 的应用设置设置为 falseYes, you need to set an app setting called WEBSITE_WEBDEPLOY_USE_SCM to false.

使用 Linux Web 应用时,应用程序的 Git 部署失败。如何解决此问题?Git deployment of my application fails when using Linux web app. How can I work around the issue?

如果 Linux Web 应用的 Git 部署失败,可选择以下选项之一部署应用程序代码:If Git deployment fails to your Linux web app, choose one of the following options to deploy your application code:

  • 使用持续交付(预览版)功能:可将应用的源代码存储在 Azure DevOps Git 存储库或 GitHub 存储库中,以使用 Azure 持续交付。Use the Continuous Delivery (Preview) feature: You can store your app's source code in an Azure DevOps Git repo or GitHub repo to use Azure Continuous Delivery. 有关详细信息,请参阅如何为 Linux Web 应用配置持续交付For more information, see How to configure Continuous Delivery for Linux web app.

  • 使用 ZIP 部署 API:若要使用此 API,请通过 SSH 连接到 Web 应用,并转到要在其中部署代码的文件夹。Use the ZIP deploy API: To use this API, SSH into your web app and go to the folder where you want to deploy your code. 运行以下代码:Run the following code:

    curl -X POST -u <user> --data-binary @<zipfile> https://{your-sitename}.scm.chinacloudsites.cn/api/zipdeploy
    

    如果有错误指出找不到 curl 命令,请确保在运行前一条 curl 命令之前使用 apt-get install curl 安装 curl。If you get an error that the curl command is not found, make sure you install curl by using apt-get install curl before you run the previous curl command.

语言支持Language support

我想要在 Node.js 应用程序中使用 Web 套接字,要设置什么特殊设置或配置吗?I want to use web sockets in my Node.js application, any special settings, or configurations to set?

需要,请在服务器端 Node.js 代码中禁用 perMessageDeflateYes, disable perMessageDeflate in your server-side Node.js code. 例如,如果要使用 socket.io,请使用以下代码:For example, if you are using socket.io, use the following code:

const io = require('socket.io')(server,{
  perMessageDeflate :false
});

是否支持未编译的 .NET Core 应用?Do you support uncompiled .NET Core apps?

是的。Yes.

是否支持将 Composer 用作 PHP 应用的依赖关系管理器?Do you support Composer as a dependency manager for PHP apps?

支持,在 Git 部署过程中,Kudu 应检测到正在部署 PHP 应用程序(这得益于 composer.lock 文件的存在),然后触发 composer 安装。Yes, during a Git deployment, Kudu should detect that you're deploying a PHP application (thanks to the presence of a composer.lock file), and Kudu will then trigger a composer install.

自定义容器Custom containers

我使用的是自己的自定义容器。我希望平台将 SMB 共享装载到 /home/ 目录。I'm using my own custom container. I want the platform to mount an SMB share to the /home/ directory.

如果未指定 WEBSITES_ENABLE_APP_SERVICE_STORAGE 设置,或者将其指定为 false,则 /home/ 目录不会在缩放实例之间共享,且写入的文件在重启后不会保留 。If WEBSITES_ENABLE_APP_SERVICE_STORAGE setting is unspecified or set to false, the /home/ directory will not be shared across scale instances, and files written will not persist across restarts. WEBSITES_ENABLE_APP_SERVICE_STORAGE 显式设置为 true 会启用装载。Explicitly setting WEBSITES_ENABLE_APP_SERVICE_STORAGE to true will enable the mount.

自定义容器需要很长时间才能启动,并且平台在它完成启动之前便重启了容器。My custom container takes a long time to start, and the platform restarts the container before it finishes starting up.

可以配置该平台在重启容器之前的等待时间。You can configure the amount of time the platform will wait before it restarts your container. 为此,可将 WEBSITES_CONTAINER_START_TIME_LIMIT 应用设置设为所需的值。To do so, set the WEBSITES_CONTAINER_START_TIME_LIMIT app setting to the value you want. 默认值为 230 秒,最大值为 1800 秒。The default value is 230 seconds, and the maximum value is 1800 seconds.

专用注册表服务器 URL 的格式是什么?What is the format for the private registry server URL?

提供完整注册表 URL,包括 http://https://Provide the full registry URL, including http:// or https://.

专用注册表选项中的映像名称的格式是什么?What is the format for the image name in the private registry option?

添加完整映像名称,包括专用注册表 URL(例如,myacr.azurecr.cn/dotnet:latest)。Add the full image name, including the private registry URL (for example, myacr.azurecr.cn/dotnet:latest). 使用自定义端口的映像名称无法通过门户输入Image names that use a custom port cannot be entered through the portal. 若要设置 docker-custom-image-name,请使用 az 命令行工具To set docker-custom-image-name, use the az command-line tool.

是否可以在自定义容器映像上公开多个端口?Can I expose more than one port on my custom container image?

不支持公开多个端口。We don't support exposing more than one port.

为何无法从 SCM 站点浏览自定义容器的文件系统或正在运行的进程?Why can't I browse my custom container's file system or running processes from the SCM site?

SCM 站点在单独的容器中运行。The SCM site runs in a separate container. 用户无法查看应用容器的文件系统或正在运行的进程。You can't check the file system or running processes of the app container.

我的自定义容器侦听端口 80 之外的其他端口。如何将应用配置为向该端口路由流量?My custom container listens to a port other than port 80. How can I configure my app to route requests to that port?

我们提供自动端口检测。We have automatic port detection. 也可以指定名为 WEBSITES_PORT 的应用设置,并为其提供所需的端口号值。You can also specify an app setting called WEBSITES_PORT and give it the value of the expected port number. 以前,平台使用 PORT 应用设置。Previously, the platform used the PORT app setting. 我们计划弃用此应用设置,改为独占使用 WEBSITES_PORTWe are planning to deprecate this app setting and to use WEBSITES_PORT exclusively.

是否需要在自定义容器中实现 HTTPS?Do I need to implement HTTPS in my custom container?

不需要,平台会处理共享前端上的 HTTPS 终止。No, the platform handles HTTPS termination at the shared front ends.

是否需要在代码中为内置容器使用 PORT 变量?Do I need to use PORT variable in code for built-in containers?

不需要,由于有自动端口检测,PORT 变量并不是必需的。No, PORT variable is not necessary due to automatic port detection. 如果未检测到端口,则默认使用端口 80。If no port is detected, it defaults to 80. 若要手动配置自定义端口,请使用 Dockerfile 中的 EXPOSE 说明和应用设置 WEBSITES_PORT,其中包含要在容器上绑定的端口值。To manually configure a custom port, use the EXPOSE instruction in the Dockerfile and the app setting, WEBSITES_PORT, with a port value to bind on the container.

是否需要将 WEBSITES_PORT 用于自定义容器?Do I need to use WEBSITES_PORT for custom containers?

是的,这是自定义容器所必需的。Yes, this is required for custom containers. 若要手动配置自定义端口,请使用 Dockerfile 中的 EXPOSE 说明和应用设置 WEBSITES_PORT,其中包含要在容器上绑定的端口值。To manually configure a custom port, use the EXPOSE instruction in the Dockerfile and the app setting, WEBSITES_PORT, with a port value to bind on the container.

在 Docker 映像中使用 ASPNETCORE_URLS?Can I use ASPNETCORE_URLS in the Docker image?

是,可以在 .NET core 应用启动之前覆盖环境变量。Yes, overwrite the environmental variable before .NET core app starts. 例如E.g. 在 init.sh 脚本中:导出 ASPNETCORE_URLS={Your value}In the init.sh script: export ASPNETCORE_URLS={Your value}

多容器与 Docker Compose 结合使用Multi-container with Docker Compose

如何将 Azure 容器注册表 (ACR) 配置为用于多容器?How do I configure Azure Container Registry (ACR) to use with multi-container?

若要将 ACR 用于多容器,所有容器映像 都必须托管在同一台 ACR 注册表服务器上。In order to use ACR with multi-container, all container images need to be hosted on the same ACR registry server. 在将它们托管在同一台注册表服务器上之后,需要创建应用程序设置,然后更新 Docker Compose 配置文件,使之包含 ACR 映像名称。Once they are on the same registry server, you will need to create application settings and then update the Docker Compose configuration file to include the ACR image name.

创建以下应用程序设置:Create the following application settings:

  • DOCKER_REGISTRY_SERVER_USERNAMEDOCKER_REGISTRY_SERVER_USERNAME
  • DOCKER_REGISTRY_SERVER_URL(完整 URL,例如:https://<server-name>.azurecr.cnDOCKER_REGISTRY_SERVER_URL (full URL, ex: https://<server-name>.azurecr.cn)
  • DOCKER_REGISTRY_SERVER_PASSWORD(在 ACR 设置中启用管理员访问权限)DOCKER_REGISTRY_SERVER_PASSWORD (enable admin access in ACR settings)

在配置文件内引用 ACR 映像,如下例所示:Within the configuration file, reference your ACR image like the following example:

image: <server-name>.azurecr.cn/<image-name>:<tag>

怎么知道哪个容器可以访问 Internet?How do I know which container is internet accessible?

  • 只能打开一个容器进行访问Only one container can be open for access
  • 只能访问端口 80 和 8080(公开的端口)Only port 80 and 8080 is accessible (exposed ports)

以下规则用于确定哪个容器可供访问 — 按优先顺序排列:Here are the rules for determining which container is accessible - in the order of precedence:

  • 设置为容器名称的应用程序设置 WEBSITES_WEB_CONTAINER_NAMEApplication setting WEBSITES_WEB_CONTAINER_NAME set to the container name
  • 第一个定义端口 80 或 8080 的容器The first container to define port 80 or 8080
  • 如果以上规则均不适用,则文件中定义的第一个容器将可供访问(公开)If neither of the above is true, the first container defined in the file will be accessible (exposed)

Web 套接字Web Sockets

Linux 应用支持 Web 套接字。Web Sockets are supported on Linux apps.

重要

免费应用服务计划中的 Linux 应用目前不支持 Web 套接字。Web Sockets are not currently supported for Linux apps on Free App Service Plans. 我们正在努力消除此限制,并计划在免费应用计划中最多支持 5 个 Web 套接字连接。We are working on removing this limitation and plan to support up to 5 web socket connections on Free App Service plans.

定价和 SLAPricing and SLA

服务正式版的定价是多少?What is the pricing, now that the service is generally available?

定价因 SKU 和区域而异,但你可以在我们的定价页上查看更多详细信息:应用服务定价Pricing varies by SKU and region but you can see more details at our pricing page: App Service Pricing.

其他问题Other questions

“请求的功能在资源组中不可用”是什么意思?What does "Requested feature is not available in resource group" mean?

使用 Azure 资源管理器 (ARM) 创建 Web 应用时,你可能会看到此消息。You may see this message when creating web app using Azure Resource Manager (ARM). 根据当前的限制,对于同一资源组,不能在同一区域中混合使用 Windows 和 Linux 应用。Based on a current limitation, for the same resource group, you cannot mix Windows and Linux apps in the same region.

应用程序设置名称中支持的字符有哪些?What are the supported characters in application settings names?

应用程序设置只能使用字母(A-Z、a-z)、数字 (0-9) 和下划线字符 ()。You can use only letters (A-Z, a-z), numbers (0-9), and the underscore character () for application settings.

可在何处请求新功能?Where can I request new features?

可以在 Web 应用反馈论坛提交看法。You can submit your idea at the Web Apps feedback forum. 请将“[Linux]”添加到建议的标题中。Add "[Linux]" to the title of your idea.

后续步骤Next steps