86

After the latest updates to gcloud and docker I'm unable to access images on my google container repository. Locally when I run: gcloud auth configure-docker as per the instructions after updating gcloud, I get the following message:

WARNING: `docker-credential-gcloud` not in system PATH.
gcloud's Docker credential helper can be configured but it will not work until this is corrected.
gcloud credential helpers already registered correctly.

Running which docker-credential-gcloud returns docker-credential-gcloud not found.

I have no other gcloud-related path issues and for the life of me can't figure out how to install/add docker-credential-gcloud to path. Here's what I have installed (shown via gcloud version):

Google Cloud SDK 197.0.0
beta 2017.09.15
bq 2.0.31
container-builder-local
core 2018.04.06
docker-credential-gcr
gsutil 4.30

I also have Docker CE Version 18.03.0-ce-mac60 (23751).

Here's my $PATH:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

I also ran source /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.zsh.inc on original gcloud install.

ZaxR
  • 4,896
  • 4
  • 23
  • 42
  • How did you install `gcloud`? `docker-credential-gcloud` should normally be co-located with `gcloud` itself within the same folder on your path. – jsand Apr 11 '18 at 17:23
  • Also, if you have already have `docker-credential-gcr`, you can continue using it instead, presuming `docker-credential-gcr configure-docker` works without incident... – jsand Apr 11 '18 at 17:25
  • Looks like my only missing step was to have completely closed the terminal and restarted...stupid mistake. Thanks for looking into this :) – ZaxR Apr 11 '18 at 18:10
  • I actually installed `docker-credential-gcr` because `docker-credential-gcloud` wasn't co-located with gcloud. Still interested in an answer to how to fix that... – ZaxR Apr 11 '18 at 18:12
  • What method did you use to install `gcloud`? How did you download it? – jsand Apr 11 '18 at 18:13
  • `brew cask install --appdir="/Applications" google-cloud-sdk` – ZaxR Apr 11 '18 at 18:14
  • Seems like the Homebrew installation method doesn't include some of the standard utilities that are included with other installations. Thanks! – jsand Apr 11 '18 at 18:22
  • Do you know which utilities/have a link you can share? What install method do you recommend? – ZaxR Apr 11 '18 at 18:34
  • I did a fresh install via the instructions at https://cloud.google.com/sdk/docs/quickstart-macos and I'm back to square one. Credentials store error: StoreError('docker-credential-gcr not installed or not available in PATH' – ZaxR Apr 11 '18 at 20:30
  • Here's our getting started doc: https://cloud.google.com/container-registry/docs/quickstart – jsand Apr 11 '18 at 20:47
  • Does `gcloud auth configure-docker` work now for you? Did you use the install script? What's the output of `which gcloud`? – jsand Apr 11 '18 at 20:48
  • Do you use `docker` with `sudo`? In that case, you need to also run `configure-docker` as sudo. – jsand Apr 11 '18 at 20:50
  • Ended up figuring it out the missing step with https://github.com/docker/for-mac/issues/1396 . Still requires docker-credential-gcr though. Yes to `gcloud auth configure-docker` and `which gcloud` correctly points to where I manually put the folder (in home). I use docker w/o sudo. – ZaxR Apr 11 '18 at 21:07
  • 1
    Excellent, glad you found the root cause. I'm guessing that `docker-credential-gcr` was giving you errors because the gcloud SDK's bin directory got wiped out during your re-install. – jsand Apr 12 '18 at 00:46
  • Just delete `.docker/config.json` https://superuser.com/a/1411019/1238179 – Victor Barros Nov 06 '20 at 20:28

12 Answers12

98

Notice: All docker-credential-gcr below can be replaced with docker-credential-gcloud. I think it is just different versions of gcloud, I might be wrong.

I used Homebrew Cask to install gcloud too. I installed docker-credential-gcr with

$ gcloud components install docker-credential-gcr

And then like you said, which docker-credential-gcr doesn't gave you anything.

So I ran which gcloud to find there is a symlink to gcloud in /usr/local/bin. This symlink is created by Homebrew when you installed gcloud at first place. Now docker-credential-gcr wasn't installed by Homebrew but by gcloud itself, so there isn't a symlink.

I called readlink /usr/local/bin/gcloud and found out gcloud is installed in /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin/.

Then:

$ ls /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin

There you should see docker-credential-gcr listed there.

I simply linked it to /usr/local/bin:

$ ln -s \
    /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin/docker-credential-gcr \
    /usr/local/bin/

Then run:

$ docker-credential-gcr configure-docker

It should succeed.

Denilson Sá Maia
  • 47,466
  • 33
  • 109
  • 111
Xiwen Li
  • 1,155
  • 8
  • 15
  • 8
    This answer almost worked for me, but needed a tweak. The symlink step seemed to have an outdated/typo in it. It referenced `docker-credential-gcr` instead of `docker-credential-gcloud`. Updating that step as below worked for me. `$ ln -s /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin/docker-credential-gcloud /usr/local/bin/` – jumand Apr 24 '18 at 22:53
  • Thank you Jumand for noticing it. It was pure type. I am having it corrected. – Xiwen Li Apr 26 '18 at 02:02
  • I just checked. On my machine it is docker-credential-gcr. And I ran `gcloud components list` docker-credential-gcloud isn't there. I don't know what's going on. – Xiwen Li Apr 26 '18 at 02:14
  • 1
    @jumand - I think that `docker-credential-gcr` is the new tool, and `-gcloud` is the deprecated one. See https://cloud.google.com/container-registry/docs/advanced-authentication – Maximilian May 03 '18 at 05:13
  • 2
    for me it was not in `/usr/local/Caskroom/` but in `/snap/` (using ubuntu) – Inbar Rose Feb 21 '19 at 10:08
31

Just had the same issue on Windows, running Docker with Linux containers, Docker engine v19.03.8. Using docker compose. I do not use gcloud for my dockerfiles...

DT1001 dockerpycreds.errors.InitializationError: docker-credential-gcloud not installed or not available in PATH

  1. Option 1: Edit the docker configuration file and remove all gcloud entries from there.

    • Windows c:/Users/<your account>/.docker/config.json

    • Linux & MacOS ~/.docker/config.json

  2. Option 2: Go to Troubleshoot -> Reset to factory defaults.

After this my docker compose was creating containers and running the images without any issues.

Mohamed Elzarei
  • 515
  • 3
  • 20
Milen
  • 8,697
  • 7
  • 43
  • 57
  • 3
    I had to make credHelpers empty `"credHelpers":{}`. thanks worked for me. – Amir Chatrbahr Feb 05 '21 at 01:09
  • 1
    I also cleared `"credHelpers":{}` as mentioned by @amir-chatrbahr, but it was filled again. I assume it can come from updating Docker Desktop or IntelliJ (where I have an unconfigured GCloud plugin)? – Dirk Feb 21 '21 at 11:24
  • I was having the same problem trying to `docker-compose build` locally, after uninstalling gcloud, so after removing both files it worked fine: `/usr/bin/docker-credential-gcloud` and `~/.docker/config.json` – bzani Apr 07 '21 at 19:40
  • Helped just to remove `~/.docker/config.json` and restart Docker. – av-k May 13 '22 at 12:47
7

On MacOS

Step 1:

Install gcloud and docker-credential-gcr, following this tutorial

Step 2:

$ ln -s /usr/local/google-cloud-sdk/bin/docker-credential-gcr /usr/local/bin/docker-credential-gcloud

Step 3:

$ rm -rf ~/.docker

Step 4:

$ docker-compose build --pull

Finished!

2240
  • 1,547
  • 2
  • 12
  • 30
Johnson Chen
  • 121
  • 1
  • 4
4

Never found a way to directly resolve the docker-credential-gcloud issue, but the following got me up and running again. WARNING: the following will delete all your existing docker images and install a bunch of gcloud utilities:

  1. gcloud components install docker-credential-gcr,
  2. Restart the terminal completely
  3. docker-credential-gcr configure-docker.
  4. screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty

  5. umount /var/lib/docker/overlay2

  6. rm -rf /var/lib/docker
  7. Restart the terminal completely.
ZaxR
  • 4,896
  • 4
  • 23
  • 42
  • On executing statement 3 we received this warning. Any concern? "...WARNING: Unable to execute `docker version`: exit status 1 This is expected if `docker` is not installed, or if `dockerd` cannot be reached..." – Praxiteles Jul 27 '18 at 06:04
  • I don't remember encountering that, but the accepted answer makes a lot more sense than this one I think – ZaxR Jul 27 '18 at 21:33
3

The new version of google-cloud-sdk has only docker-credential-gcr but not docker-credential-gcloud anymore. On the other hand one of my python packages always requested docker-credential-gcloud.

The solution was to symlink docker-credential-gcloud to docker-credential-gcr:

ln -s /path/to/google-cloud-sdk/bin/docker-credential-gcr /usr/local/bin/docker-credential-gcloud

ls -l /usr/local/bin | grep docker should now print:

...
docker-credential-gcloud -> /path/to/google-cloud-sdk/bin/docker-credential-gcr
...
Tobias Ernst
  • 4,214
  • 1
  • 32
  • 30
2

Usually, this error indicates that your $PATH variable has been clobbered by a package or program you have recently installed so that the Google Cloud SDK can't be found.

$PATH is altered by many programs when they install by altering ~/.profile, ~/.bash_profile or ~/.bashrc or their non-bash equivalents. With a bad $PATH, Google Cloud SDK is configured in docker but can't be seen as executables so we get this error. This assumes you have used the Google Cloud SDK in the past, but if gcloud is configured with your docker then you probably have. Don't reinstall gcloud or disable it, you already have it on your system and that is fine.

The solution then is to fix your $PATH, not to install anything.

echo $PATH

This should be a pretty long : delimited list of directories that your files are in. Do you see a google-cloud-sdk/bin in the string? Is the string way too short given all the trouble you've gotten into in your life on this computer? You use NVM but it is missing? Use Homebrew but it is missing? Try brew from the command line, does it work?

If the answer is "no" to any of the above, inspect the files above to see if there are any new entries at the bottom of each that might have broken things. Did you just install anything new?

Something is clobbering your $PATH and you need to figure out what that is. For me it is usually something to do with Anaconda Python via the conda init command. For you it might be nvm or something else. Figure out what it is and fix the problem. Don't start over with a new $PATH and install the same stuff over again or disable gcloud authentication.

rjurney
  • 4,824
  • 5
  • 41
  • 62
1

It really seems to be something with the Homebrew Cask. I uninstalled the cask and then reinstalled the Google Cloud SDK by manually downloading the tar ball and running the packaged install script as described there.

Now docker-credential-gcloud is in my path:

$ which docker-credential-gcloud
/Users/moritz/google-cloud-sdk/bin/docker-credential-gcloud
anothernode
  • 5,100
  • 13
  • 43
  • 62
  • This worked for me. For the love of god I couldn't find the executable and was about to clone and run the repo. After extracting ran: `./google-cloud-sdk/bin/gcloud init` then `./google-cloud-sdk/bin/gcloud components install docker-credential-gcr` then just add the bin to your `$PATH` – asdfqwer Oct 14 '20 at 22:40
1

I can't figure out what Google is trying to achieve here. On Linux there is docker-credential-gcloud and on Windows there is docker-credential-gcr.exe, and then there is docker-credential-gcloud.cmd which calls gcloud auth docker-helper. This is kind of a nightmare if you're trying to write portable build scripts or gradle rules because not everything seems capable of finding and calling docker-credential-gcloud.cmd when you exec docker-credential-gcloud... it might work from the dos prompt, but in general doesn't work.

After a ton of fooling around with .bat scripts, cygwin scripts, .cmd scripts and so forth, I found the best solution was to go into the gcloud installation and just copy docker-credential-gcr.exe docker-credential-gcloud.exe ... not a very satisfying solution, but is the only thing I found that would do the trick.

xpusostomos
  • 1,309
  • 11
  • 15
0

I got the issue when I tried to SSH from Google Cloud Build into an Engine VM Instance, so I had

steps:
- name: 'gcr.io/cloud-builders/gcloud'
  args: ['compute', 'ssh',
         '--project', '$PROJECT_ID',
         '--zone', 'asia-southeast1-b',
         '--strict-host-key-checking=no',
         'username@instance-1',
         '--command' ,'sh start.sh'

My start.sh

#!/bin/sh

echo "Started: $(date --iso-8601=seconds)"

docker pull gcr.io/aaa/bbbc/cccc

echo "Finished: $(date --iso-8601=seconds)"

The issue was How to set PATH when running a ssh command?

https://unix.stackexchange.com/questions/332532/how-to-set-path-when-running-a-ssh-command

vanduc1102
  • 5,769
  • 1
  • 46
  • 43
0

So I just faced the same problem where I am trying to pull an image from GCR to an GCP instance and want to share my solution.

I ran gcloud auth configure-docker and got the warning:

WARNING: `docker-credential-gcloud\` not in system PATH.
gcloud's Docker credential helper can be configured but it will not work until this is corrected.

I applied the accepted answer for this thread and ran gcloud components install docker-credential-gcr and got a long error:

ERROR: (gcloud.components.install) You cannot perform this action because this Cloud SDK installation is managed by an external package manager.
Please consider using a separate installation of the Cloud SDK created through the default mechanism described at: https://cloud.google.com/sdk/

When no solution was working, I uninstalled the Google provided google-cloud-sdk package that was installed via snap and instlled with distro specifice package manager, for me that is apt-get as instructed in the Installing Google Cloud SDK: Installation options page and re-ran the gcloud auth configure-docker and this time it solved my problem.

Fazle Rabbi
  • 231
  • 1
  • 5
  • 17
0

In my case the problem was due to how WSL 1 works with Docker on Windows. At first I only installed and initialized gcloud in WSL Ubuntu, not in Windows. However as Docker daemon is actually run by Windows, you need to install gcloud for Windows as well (and don't forget to run all of the inits and authorizations there).

Martin D
  • 667
  • 1
  • 10
  • 25
0

On Windows 10/11, you need to ensure that C:\Users\USERNAME\AppData\Local\Google\Cloud SDK\google-cloud-sdk\bin\ is added to your system $PATH environment variable. It may not have been added if the Google Cloud SDK was not able to add it during GCloud installation. So add it manually like this:

  1. Windows Task Bar ➔ Press the search icon or the search bar
  2. Type "environment" ➔ and click on "Edit the System Environment Variables" (ensure that you have Administrator access)
  3. At the bottom of the dialog, click the Environment Variables... button
  4. System Variables ➔ click PathEdit...New ➔ paste in C:\Users\USERNAME\AppData\Local\Google\Cloud SDK\google-cloud-sdk\bin\ (replace "USERNAME" with your username)
  5. Close and restart any open Command Prompt windows.

Then verify on the Git Bash for Windows console:

  1. Optional: Note that the AppData folder is hidden by default, so you may want to unhide AppData first, to see its contents.
  2. Restart the Git Bash Terminal window
  3. echo $PATH ➔ This should print a long string that contains: :/c/Users/USERNAME/AppData/Local/Google/Cloud SDK/google-cloud-sdk/bin
  4. where docker-credential-gcloud ➔ This should print C:\Users\USERNAME\AppData\Local\Google\Cloud SDK\google-cloud-sdk\bin\docker-credential-gcloud.cmd
Mr-IDE
  • 7,051
  • 1
  • 53
  • 59