These instructions are to create a local, named Docker volume that stores authenticated Google service account credentials, for mounting to local Docker containers. This setup should only be required once, as the volume persists even after connected containers are stopped/removed.
TREAT THIS VOLUME AS CREDENTIALS. The volume stores sensitive information and should never leave your local machine.
Steps
-
Create the service account credentials file to authenticate google services.
This file should be saved in~/.config/gcloud/
on Mac/Linux, orC:\Users\
on Windows. -
Download and save one of the scripts below into the same directory as your credentials. Use the bash script on Mac, Linux, or via properly configured Git BASH or WSL2 on Windows. Use the powershell script on Windows otherwise.
-
Run the script. Note the quotes around the Windows path are required.
Mac/Linux:
cd ~ chmod 775 local-credentials-setup.sh ./local-credentials-setup.sh /Users/<YOUR USER>/.config/gcloud/<YOUR SERVICE ACCOUNT FILE>.json <YOUR GOOGLE PROJECT>
Windows:
./local-credentials-setup.ps1 "C:\Users\<YOUR USERD>\<YOUR SERVICE ACCOUNT FILE>.json"
-
Test that setup worked.
$ docker run -v credentials-gcloud:/root/.config/gcloud google/cloud-sdk:latest gcloud config list [core] account = [email protected] disable_usage_reporting = True project = <YOUR PROJECT> Your active configuration is: [default]
-
(Optional) Delete the setup script.