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.

Solution

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

$ gcloud auth application-default

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:

volumes:
- ~/.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.

Show your support

Clapping shows how much you appreciated Kevin Simper’s story.