Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pushing an image to Google Container Registry from inside a Docker container

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?

like image 418
Rtsne42 Avatar asked Oct 20 '25 16:10

Rtsne42


1 Answers

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
like image 132
Rtsne42 Avatar answered Oct 23 '25 06:10

Rtsne42



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!