Reputation: 527
I'm currently trying to push a Docker image to my Container Registry this is the only command that is used in the documentation:
gcloud docker -- push gcr.io/my_project/foo:v1
But since I run the google-cloud-sdk
inside a Docker container I can't use gcloud docker ...
because Docker is running on the host.
Is there some way I could push the image to the Container Registry without having to install the google-cloud-sdk
on my local filesystem?
Upvotes: 3
Views: 3975
Reputation: 86
It's worth mentioning that Google Container Registry is going to be soon deprecated and is replaced by Google Artifact Registry.
With the new approach, above answer will no longer work. If you are looking for guidance, see the docs below:
https://cloud.google.com/artifact-registry/docs/docker/store-docker-container-images#push
Upvotes: 1
Reputation: 527
I managed to find an answer myself but for reference I won't delete the question but instead just post the answer.
In order to push Docker images directly from the docker
client to the Google Container Registry you need to use the docker login
command together with the authentication token for your Google Cloud project.
To get an authentication token for your Google Cloud project use:
gcloud auth application-default print-access-token
Then use that token to log in to the Google Cloud with docker
:
docker login -u oauth2accesstoken -p "token_goes_here" https://gcr.io
If the login has been successfull you should now be able to push images directly to the Google Container Registry:
docker push gcr.io/my_project/foo:v1
Upvotes: 5