问题
I'm trying to log in to Google's Container Registry on Windows 10 by using a JSON Key file. I have this working without issues on my Mac so the keyfile is definitely working.
First off I had issues getting the docker login function to accept the contents of the JSON key file. I've tried running the "/set /p PASS..." command in CMD and I've tried something along the lines of this in Powershell:
docker login -u _json_key -p "$(Get-Content keyfile.json)" https://gcr.io
These all result in either an error or this:
"docker login" requires at most 1 argument.
Since I couldn't get this to work, I ran:
docker login -u _json_key https://gcr.io
And then just removed all breaks from the JSON file manually, copied it to clipboard and pasted it when prompted for my password.
That results in:
Login Succeeded
Problem solved! Right?
Well apparently not. I was still unable to pull my images and when I ran docker info the only registry listed was "https://index.docker.io/v1/".
I've tried starting Powershell as admin, and restarted and reset docker but nothing seems to help.
Anyone got any clue what is going on? How do I debug this?
I'm running Docker version 17.12.0 (stable)
回答1:
I found a solution that works for both Windows (in PowerShell) and bash. The secret is to use the "provide a password using stdin".
cat gcr_registry-ro.json | docker login -u _json_key --password-stdin https://gcr.io
Login Succeeded
Help text and versions:
PS C:\Users\andy> docker login --help
Usage: docker login [OPTIONS] [SERVER]
Log in to a Docker registry
Options:
-p, --password string Password
--password-stdin Take the password from stdin
-u, --username string Username
PS C:\Users\andy> docker -v
Docker version 18.06.1-ce, build e68fc7a
PS C:\Users\andy>
回答2:
I got it working now by using the trick I did with removing all line breaks in the key, copying it and then pasting it when I'm prompted for my password, instead of trying to pass it into the -p parameter. Turns out I had to change the url to eu.gcr.io instead of just gcr.io.
I wrote some feedback on the GCR documentation page - Hopefully they'll fix it and maybe even add the correct way to do it in Powershell.
Only thing I'm still wondering is why I can't see that I'm logged into GCR in docker info.
来源:https://stackoverflow.com/questions/48310486/docker-login-to-gcr-io-in-powershell