Accessing Google cloud services from Docker container

Alon Barad
Feb 4, 2021

First of all, we need to make sure that we have an authentication file on the host, we can check it by checking if the auth file exists:

cat ~/.config/gcloud/application_default_credentials.json # Linux

The output should look like this:

{
"client_id": "<ID>.apps.googleusercontent.com",
"client_secret": "<SECRET>",
"refresh_token": "<TOKEN>",
"type": "authorized_user"
}

If the file does not exist, you can create it by authenticating to Google using the following gcloud command from the host.

  • make sure you have gcloud installed on your machine.
gcloud auth application-default login

That saves the authentication data into a file.

Now we want to mount our authentication file to our container, all we need to do is edit the docker-compose.yml and add the following lines:

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

This will make the `google-cloud` package look in the right path for authentication.

That it!

Great success!

--

--