繁体   English   中英

Azure - 如何使用 Container Registry 将 Docker 执行到容器中?

[英]Azure - how do I Docker exec into container with a Container Registry?

我想将docker exec到 Azure 托管的容器中。

然而,在 Azure 中似乎有几种托管容器的方法,而且我发现的大多数指南和信息似乎都引用了我们如何设置它的不同方法。

由于图像被添加为“容器注册表”中的“回购”,我们的容器正在运行。 除此之外,Azure 中还有称为容器组和容器实例的东西,据我所知,这两者都与我的设置无关。

那么我怎样才能执行到以这种方式托管的容器中呢?

本 MS 指南所述,这是我尝试过的方法,但同样,这似乎假定容器组/容器实例方法,而不是我的设置。

az container exec --resource-group unitsnew --name unitsreg --exec-command "whatever"

unitsnew是我的资源组的名称, unitsreg是我在容器注册表中的 repo 名称(我也尝试过为此 arg 传递注册表本身的名称。)

因此,这是行不通的; 有人告诉我:

(ResourceNotFound) 资源“Microsoft.ContainerInstance/containerGroups/unitsreg”。 在资源组“unitsnew”下未找到。 有关详细信息,请拨打 go 至https://aka.ms/ARMResourceNotFoundFix代码:ResourceNotFound 消息:未找到资源组“unitsnew”下的资源“Microsoft.ContainerInstance/containerGroups/unitsreg”。 欲了解更多详情,请拨打 go 至https://aka.ms/ARMResourceNotFoundFix

[ - - 编辑 - - ]

设置信息。

appslot 将其“源”(在部署中心 > 设置下)设置为“容器注册表”。

注册表设置为:

  • 容器类型 = 单个容器
  • 注册表源 = ACR
  • 注册表=
  • 图片=
  • Tag = 'latest'(在 Pipelines YAML 中规定)
  • 启动文件: bin/rails server --port 3000 --binding 0.0.0.0

正如我所说,这与具有以下 YAML 的 Devops 管道相关联:

# Docker
# Build and push an image to Azure Container Registry
# https://learn.microsoft.com/azure/devops/pipelines/languages/docker

trigger:
  - my-gh-branch

resources:
  - repo: self

variables:
  imageRepository: 'panstudiohellolamppostapi_web'
  containerRegistry: '<redacted>.azurecr.io'
  dockerfilePath: '$(Build.SourcesDirectory)/Dockerfile'
  tag: 'latest'

  # Agent VM image name
  vmImageName: 'ubuntu-latest'

stages:
  - stage: Build
    displayName: Build and push stage
    jobs:
      - job: Build
        displayName: Build
        pool:
          vmImage: $(vmImageName)
        steps:
          - task: DockerCompose@0
            inputs:
              containerregistrytype: 'Azure Container Registry'
              azureSubscription: 'Microsoft Azure Sponsorship(<redacted>)'
              azureContainerRegistry: '{"loginServer":"<redacted>.azurecr.io", "id" : "/subscriptions/<redacted>/resourceGroups/<redacted>/providers/Microsoft.ContainerRegistry/registries/<redacted>"}'
              dockerComposeFile: '**/docker-compose.yml'
              action: 'Run a Docker Compose command'
              dockerComposeCommand: 'build'
          - task: DockerCompose@0
            inputs:
              containerregistrytype: 'Azure Container Registry'
              azureSubscription: 'Microsoft Azure Sponsorship(<redacted>)'
              azureContainerRegistry: '{"loginServer":"<redacted>.azurecr.io", "id" : "/subscriptions/<redacted>/resourceGroups/<redacted>/providers/Microsoft.ContainerRegistry/registries/<redacted>"}'
              dockerComposeFile: '**/docker-compose.yml'
              action: 'Push services'

据我了解,错误消息引起了轰动。 az 正在寻找容器组的正在运行的容器。

正如您所看到的,az 提供的帮助消息:


 az container exec
 the following arguments are required: --exec-command

 Examples from AI knowledge base:
 az container exec --exec-command "/bin/bash" --name mynginx --resource-group MyResourceGroup
 Execute a command from within a running container of a container group. (autogenerated)

 az container exec --resource-group MyResourceGroup --name mynginx --container-name nginx --exec-command "/bin/bash"
 Stream a shell from within an nginx container.

 https://learn.microsoft.com/en-US/cli/azure/container#az_container_exec
 Read more about the command in reference docs


 az container exec --resource-group MyResourceGroup --name mynginx --container-name nginx --exec-command "/bin/bash"
 Stream a shell from within an nginx container.

 https://learn.microsoft.com/en-US/cli/azure/container#az_container_exec
 Read more about the command in reference docs

据我了解,您只将图像推送到 azure ACR。 将图像推送到 Azure ACR 不足以让容器运行,Azure ACR 功能类似于 Dockerhub,它存储您的工件,例如 docker 图像。 如果你想让你的图像运行,你可以使用容器组https://learn.microsoft.com/en-us/azure/container-instances/container-instances-container-groups

希望有所帮助:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM