“gcloud auth configure-docker” on GCP VM instance with Ubuntu not setup properly?

醉酒当歌 提交于 2020-02-02 04:32:27

问题


I created a VM instance on GCP using Ubuntu 18.10. When I SSH the VM without any modification and try:

gcloud info

I got some Warning:

System PATH: [/snap/google-cloud-sdk/66/usr/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/game
s:/snap/bin]
Python PATH: [/snap/google-cloud-sdk/66/lib/third_party:/snap/google-cloud-sdk/66/lib:/snap/google-cloud-sdk/66/usr/lib/python2.7/:/snap
/google-cloud-sdk/66/usr/lib/python2.7/plat-x86_64-linux-gnu:/snap/google-cloud-sdk/66/usr/lib/python2.7/lib-tk:/snap/google-cloud-sdk/6
6/usr/lib/python2.7/lib-old:/snap/google-cloud-sdk/66/usr/lib/python2.7/lib-dynload]
Cloud SDK on PATH: [False]
Kubectl on PATH: [False]
WARNING: There are old versions of the Google Cloud Platform tools on your system PATH.
  /usr/bin/snap

If I try to authenticate with:

sudo gcloud auth configure-docker

I see:

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.
WARNING: `docker` not in the system PATH.
`docker` and `docker-credential-gcloud` need to be in same PATH in order to work correctly together.
gcloud's Docker credential helper can be configured but it will not work until this is corrected.
The following settings will be added to your Docker config file 

It seems that a quite recent version of gcloud is installed:

sudo gcloud version

Google Cloud SDK 230.0.0
alpha 2019.01.11
beta 2019.01.11
bq 2.0.39
core 2019.01.11
gsutil 4.35
kubectl 2019.01.11

It doesn't seem I am allowed to update gcloud on such instance.

Then I installed Docker and pulled a docker image.

sudo snap install docker
sudo docker pull tensorflow/serving

This is working fine. The issue is that I cannot push the image on GCP Container Registry:

sudo docker tag tensorflow/serving gcr.io/xxx/tf-serving
sudo docker push gcr.io/xxx/tf-serving
Unauthorized: You don't have the needed permissions to perform this operation, and you may have invalid credentials. To authenticate your request
st, follow the steps in https://cloud.google.com/container-registry/docs/advanced-authentication

and in the link it is explained that I need to run:

sudo gcloud auth configure-docker

How do I fix the issue? The issue is already present when I SSH the VM ?

WARNING: `docker-credential-gcloud` not in system PATH.

I can push the image on DockerHub without any issue.

I tried to reinstall google-cloud-sdk:

sudo apt-get update && sudo apt-get install google-cloud-sdk

But now I need to use:

sudo gcloud alpha auth configure-docker

and the end I still cannot push the image.

It seems to be related to some path issue:

Cloud SDK on PATH: [False]
Kubectl on PATH: [False]
WARNING: There are old versions of the Google Cloud Platform tools on your system PATH.
  /usr/bin/snap

Any idea? I did follow the GCP documentation step by step. I also look at GCP IAM to grant some access on my bucket.

I am new on GCP and Cloud so I am probably missing something obvious. By the way, I need to build a Docker image using a shell script so I need to use such type of VM because on the other VM for which a lot of stuff is already pre-installed are mounted with "noexec" flag.


回答1:


The Snap package contains docker-credential-gcloud in /snap/google-cloud-sdk/current/bin/. You can symlink it to /usr/local/bin using:

sudo ln -s /snap/google-cloud-sdk/current/bin/docker-credential-gcloud /usr/local/bin

After that, pushing Docker images to Google Container Registry (gcr.io) works fine.

I also tried sudo snap alias google-cloud-sdk.docker-credential-gcloud docker-credential-gcloud to create a symlink similar to the one for gcloud itself. But that failed with the following error:

error: cannot perform the following tasks:
- Setup manual alias "docker-credential-gcloud" => "docker-credential-gcloud" for snap "google-cloud-sdk" (cannot enable alias "docker-credential-gcloud" for "google-cloud-sdk", target application "docker-credential-gcloud" does not exist)



回答2:


Here is what is now working (thanks Google for the help)

Setup:

  • Choose Ubuntu 18.10 (GNU/Linux 4.18.0-1005-gcp x86_64)
    add 20 GB disk + allow http and http
    set access for each API -> Storage : Read Write
  • sudo snap remove google-cloud-sdk
  • curl https://sdk.cloud.google.com | bash
  • reconnect to the VM
  • install docker https://docs.docker.com/install/linux/docker-ce/ubuntu/
    sudo apt-get remove docker docker-engine docker.io containerd runc
    sudo apt-get update
    sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    sudo add-apt-repository \
    "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
    $(lsb_release -cs) \
    stable"
    sudo apt-get update
    sudo apt-get install docker-ce docker-ce-cli containerd.io
    sudo docker run hello-world # test
  • sudo usermod -a -G docker LOGIN
  • reconnect to the VM
  • gcloud auth configure-docker

testing docker pull/push on GCP

  • docker pull tensorflow/serving
  • docker tag tensorflow/serving gcr.io/BUCKET_NAME/tf-serving
  • docker push gcr.io/BUCKET_NAME/tf-serving
    (if you don't give write access when creating the VM: use "gcloud auth login")

now this works




回答3:


the issue might be that snap install; just remove /snap/google-cloud-sdk from the system. or check which gcloud to see which one is even used. the apt version does not seem to have these docker packages available - and also, the $PATH only lists that snap version.

ordinary, components can be updated with:

gcloud components update

or listed:

gcloud components list

or installed:

gcloud components install docker-credential-gcr 

would suggest to simply install the stand-alone version with:

curl https://sdk.cloud.google.com | bash

after having removed the snap and apt version, from file-system and $PATH.



来源:https://stackoverflow.com/questions/54494386/gcloud-auth-configure-docker-on-gcp-vm-instance-with-ubuntu-not-setup-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!