如何在 Azure DevOps 流水线中运行 "docker login azure"?

5

我有一个 shell 脚本,可以使用 Azure CLI(在 Linux 上)将容器部署到 Azure 容器实例中,本地运行正常,但是我在管道任务中执行 Azure 登录时遇到了问题。

在本地,以下命令将打开浏览器进行登录:

docker login azure

文档建议在管道任务中传递客户端 ID 和客户端密钥来执行相同操作。我认为应该像这样:

docker login azure --client-id $servicePrincipalId --client-secret $servicePrincipalKey --tenant-id $tenantId

然而,在我的管道中运行此命令时,我会得到以下错误:

unknown flag: --client-id

docker login azure --help 在本地运行可以告诉我 --client-id 是有效的标志,所以我想知道在 Azure DevOps 管道中是否有其他方法可以做到这一点?


你好,你找到解决方案了吗? - Jakub Janiš
不,这种情况下我只是部署到了一个Azure虚拟机上,然后将其配置为远程Docker主机。不过我很想找到一个解决方案。 - Dave Lewis
2个回答

3

目前的问题是在Microsoft Hosted代理上没有安装Docker CLI Azure模块,可以在这里找到安装说明: https://docs.docker.com/cloud/aci-integration/

我使用的解决方法是:

- script: |
    # Add the compose-cli module; 
    curl -L https://raw.githubusercontent.com/docker/compose-cli/main/scripts/install/install_linux.sh | sh

    # Login to Azure using docker CLI, you can use variables here;
    # Note: Docker@2 task with Login Action will not help here;
    docker login azure --client-id xxx --client-secret yyy --tenant-id zzz

    # Check Context list;
    docker context aci list

    # Create ACI Context;
    docker context create aci myaci --location <Azure Location> --resource-group <RG NAME> --subscription-id <subscription ID>

    # Check It again.
    docker context list

1
Azure管道任务对Docker的支持允许您为“docker login”样式任务使用服务连接。要使用用户名/密码组合,您需要首先创建一个类型为“Docker Registry”的服务连接。然后指定类型为“other”。在这里,您可以输入您的凭据。密码是模糊的,以确保安全性。
现在,您可以在Azure DevOps管道Docker任务中使用此服务连接。
参考来源:

https://learn.microsoft.com/en-us/azure/devops/pipelines/library/service-endpoints?view=azure-devops&tabs=yaml#docker-registry-service-connection

https://learn.microsoft.com/en-us/azure/devops/pipelines/library/service-endpoints?view=azure-devops&tabs=yaml#docker-hub-or-others


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接