据我所知,类似的问题以前也曾在堆栈过流本身中被问过和回答过。但我的要求略有不同。我的要求是使用服务主体登录到Azure,我也使用下面的PowerShell脚本,
$azureAppId = "#######"
$azureAppIdPassword = "######"
$userPassword = ConvertTo-SecureString -String $azureAppIdPassword -AsPlainText -Force
$azureAppCred = (New-Object System.Management.Automation.PSCredential ($azureAppId, $userPassword))
$subscriptionId = '######'
$tenantId = '######'
Connect-AzAccount -ServicePrincipal -SubscriptionId $subscriptionId -TenantId $tenantId -Credential $azureAppCred
$containerId = Invoke-Expression -Command "docker run -d -it mcr.microsoft.com/azure-powershell"
docker exec $containerId pwsh -c Connect-AzAccount -ServicePrincipal -SubscriptionId $subscriptionId -TenantId $tenantId -Credential $azureAppCred上面的脚本与错误Connect-AzAccount: Cannot bind parameter 'Credential'. Cannot convert the "System.Security.SecureString" value of type "System.String" to type "System.Management.Automation.PSCredential".一起失败,如果我在没有停靠器的情况下执行上面的脚本,它就会运行得很好。
我尝试使用命令$azureAppCred打印docker exec $containerId pwsh -c Write-Host $azureAppCred类型,它按预期打印System.Management.Automation.PSCredential,但是登录命令仍然失败。
有人能告诉我这里可能出了什么问题吗?
谢谢你,廷图
发布于 2022-02-09 07:41:57
如本 中所述,azure登录与docker登录不同。当您使用服务主体连接azure并运行docker命令时,您可以使用如下所示的内容:
$azureAppId = "#######"
$azureAppIdPassword = "######"
$tenantId = '######'
docker login azure --client-id $azureAppId --client-secret $azureAppIdPassword --tenant-id $tenantId
docker run -d -it mcr.microsoft.com/azure-powershellhttps://stackoverflow.com/questions/71035505
复制相似问题