gpt4 book ai didi

azure - 如何运行已经部署到azure应用程序服务容器的?

转载 作者:行者123 更新时间:2023-12-02 19:45:12 24 4
gpt4 key购买 nike

我使用 azure pipeline 来构建和部署我的 docker 容器 (ASP.Net core 3.1)。所有步骤均成功完成,我可以在 Azure 注册表和应用程序服务门户页面上看到我的容器。但似乎该实例没有在应用服务上运行,因为我只能看到“起始页面”,它建议我部署代码,并且我的 swagger 页面返回 404。

所以问题是:如何运行已经部署的管道镜像?

我的 azure 管道 yml 文件:

# Docker
# Build a Docker image
# https://learn.microsoft.com/azure/devops/pipelines/languages/docker

trigger:
- master

resources:
- repo: self

variables:
tag: '$(Build.BuildId)'

stages:
- stage: Build
displayName: Build image
jobs:
- job: Build
displayName: Build
pool:
vmImage: ubuntu-latest
steps:
# run tests
- task: DotNetCoreCLI@2
displayName: Run tests
inputs:
command: test
projects: '**/*Tests/*.csproj'
arguments: '--configuration $(buildConfiguration)'

- task: Docker@2
displayName: Build and push an image to container registry
inputs:
command: buildAndPush
repository: 'ProjectName'
dockerfile: '$(Build.SourcesDirectory)/ProjectName/API/Dockerfile'
buildContext: '$(Build.SourcesDirectory)/ProjectName/'
containerRegistry: AzureContainerRegistryConnection
tags: |
$(tag)

# Deploy stage to your App Service
- stage: Deploy
displayName: Deploy to App Service
jobs:
- job: Deploy
displayName: Deploy
pool:
vmImage: ubuntu-latest
steps:
- task: AzureWebAppContainer@1
displayName: Deploy to App Service
inputs:
azureSubscription: 'my_free_subscription(my-subscription-id)'
appName: 'app-service'
containers: 'projectnamecontainerregistry.azurecr.io/RepositoryName:$(tag)'

UPD

我不知道这是 terraform 中应用服务设置的问题

resource "azurerm_app_service_plan" "app_service_plab" {
name = "app-service-plan"
location = azurerm_resource_group.store_group.location
resource_group_name = azurerm_resource_group.store_group.name
kind = "Linux"
sku {
tier = "FREE"
size = "S1"
}
}

resource "azurerm_app_service" "app_service" {
name = "app-service"
location = azurerm_resource_group.store_group.location
resource_group_name = azurerm_resource_group.store_group.name
app_service_plan_id = azurerm_app_service_plan.app_service_plab.id
}

UPD2

开始使用新的部署任务 AzureRmWebAppDeployment@4,它确实做了一些事情,我现在甚至可以在应用程序服务计算机上看到日志。

- stage: Deploy
displayName: Deploy to App Service
jobs:
- job: Deploy
displayName: Deploy
pool:
vmImage: ubuntu-latest
steps:
- task: AzureRmWebAppDeployment@4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'free_subscription(id)'
appType: 'webAppContainer'
WebAppName: 'app-service'
DockerNamespace: 'containerregistry.azurecr.io'
DockerRepository: 'myRepository'
DockerImageTag: $(tag)
StartupCommand: 'az acr login --password $(REGISTRY_PASSWORD_UNSECRET) --username $(REGISTRY_USERNAME_UNSECRET) --name (MyRegistry)containerregistry.azurecr.io && docker run'
appSettings: |
-CONNECTION_STRING $(CONNECTION_STRING_UNSECRET)

但似乎 az acr 登录不起作用:(

现在我遇到了这样的错误

2020-09-19T19:29:08.498Z 错误 - 镜像拉取失败:验证 docker 镜像配置和凭据(如果使用私有(private)存储库)2020-09-19T19:34:00.826Z 信息 - 从 Docker 中心提取镜像:MyContainercontainerregistry.azurecr.io/MyRepo:852020-09-19T19:34:01.151Z 错误 - DockerApiException: Docker API 响应,状态代码=InternalServerError,响应={"message":"获取 https://MyContainercontainerregistry.azurecr.io/v2/MyRepo/manifests/85 :未经授权:需要身份验证,请访问 https://aka.ms/acr/authorization 了解更多信息。"}

最佳答案

使用 docker run cmd。

添加任务Docker->删除字段cmd内容并添加cmd run enter image description here

关于azure - 如何运行已经部署到azure应用程序服务容器的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63889162/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com