How to test Google Cloud services locally in Docker

The “gcloud” command-line tool is amazing, it is super simple and works without problems and you authenticate with that it opens a browser window that then sets the correct values, something that is much easier than generating access and secret token that you have to manually set in your bash config.

However with that comes the question, how do you get that auth inside a docker container running locally.

Especially now that “gcloud auth login” says:

WARNING: `gcloud auth login` no longer writes application default credentials.


We need to run this command instead that will write down the authenticating information down into a file

$ gcloud auth application-default login

That saves it to a file here:

Credentials saved to file: [/Users/kevinsimper/.config/gcloud/application_default_credentials.json]

Now you need to change your docker-compose.yml file to have this:

- ~/.config/:/root/.config

This will make the google-cloud package look for the right place for authentication.

Success, you can use gcloud components inside docker.

Like what you read? Give Kevin Simper a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.