How to call docker login --password-stdin from a powershell script

Robert Patrick 1 Reputation point
2021-08-20T14:51:20.023+00:00

I am trying to write a Powershell script that, among other things, needs to invoke docker login and use the --password-stdin arg to read the password from stdin. Here is what I am trying to do but this clearly doesn't work. Any pointers?

$proc = Write-Output "$IMAGE_REGISTRY_PUSH_PASS" | Start-Process -NoNewWindow -FilePath "$IMAGE_BUILDER_EXE" -ArgumentList "login --username $IMAGE_REGISTRY_PUSH_USER --password-stdin $IMAGE_REGISTRY_HOST" -PassThru
Wait-Process -InputObject $proc
if ($proc.ExitCode -ne 0) {
    Write-Error "Failed to log in to the image registry $IMAGE_REGISTRY_HOST"
    exit 1
}
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,627 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.