访问使用 Azure 容器注册表运行的 Azure Web 应用程序

问题描述 投票:0回答:1

编辑:解决方案是将

startup command
设置为等于我的 Docker 文件的最后一个命令,在我的例子中是
python app.py
。这可以通过 Azure 门户(转到 Azure Web 应用程序,然后转到部署中心)或运行以下命令来完成:
az webapp config show --name my-first-app --resource-group ... --startup-file="python app.py"

使用 Azure Pipelines,我的 Azure 容器注册表中现在有一个 Docker 映像。假设注册表名为

myfirstregistry
,图像名为
myfirstimage
,标签为“8”(我通过运行
az acr repository show-tags -n myfirstregistry --repository myfirstimage
确定)。

然后我使用以下命令部署了 Azure Web 应用程序:

az webapp create --name my-first-app --resource-group ... --plan ... --deployment-container-image-name myfirstregistry.azurecr.io/myfirstimage:latest

当我使用 Azure 门户访问我的 Azure Web 应用程序时,在

Overview
->
Properties
->
Web app
->
Container Image
下,它确实显示
myfirstregistry.azurecr.io/myfirstimage:8

但是当我转到我的网络应用程序时,

my-first-app.azurewebsites.net
,它显示“您的网络应用程序正在运行并等待您的内容”。 Docker 映像似乎尚未运行。我在这里缺少什么?

azure docker
1个回答
0
投票

首先,确保使用 docker run 检查 docker 镜像在本地运行良好。

 docker run -it --rm -p 8443:8443 <imagename>

如果配置任何网络规则,请确保在 Azure Web 应用程序网络部分允许相同的端口。

在您的情况下,启动命令似乎对于确保您的应用程序在 Azure Web Apps 上正确运行至关重要。当 Azure Web Apps 无法正确解释如何启动容器时,通常会出现此问题。如果 Dockerfile 中的最后一个命令是

python app.py
,则应明确将其设置为 Azure Web App 的启动命令。 您可以通过 CLI 执行相同的操作

az webapp config set --name kaaspwebappwithsql --resource-group <your-resource-group> --startup-file "python app.py"

或门户网站 enter image description here

设置启动命令后,重新启动 Azure Web App 以应用更改。
确保容器映像指向正确的版本。您提到图像标签是

8
,但您的创建命令使用了
:latest

az webapp create --name kaaspwebappwithsql  --resource-group <your-resource-group> --plan <your-plan> --deployment-container-image-name arkoacr.azurecr.io/kaaspwebappwithsql:latest

要对齐版本,您应该使用正确的标签,方法是更新 Web 应用程序的配置或在 ACR 中将所需版本显式推送为

latest

enter image description here

您可以在“监视器”->“日志”下监视您的网络应用程序以获取更多详细信息和故障排除

enter image description here

参考资料:

© www.soinside.com 2019 - 2024. All rights reserved.