0

I'm trying to pass a .json file into a Docker container at runtime but it keeps saying that keys.json was not found . I need to pass the .json file for Google Cloud's: GOOGLE_APPLICATION_CREDENTIALS

After I built the image, I have tried the following commands to no avail:

pwd = /Users/{username}/Desktop/football-data

docker run \
-e GOOGLE_APPLICATION_CREDENTIALS=keys.json \ 
-v $GOOGLE_APPLICATION_CREDENTIALS:keys.json:ro \
{image_name}:1.0
docker run \
-e GOOGLE_APPLICATION_CREDENTIALS=./keys.json \ 
-v $GOOGLE_APPLICATION_CREDENTIALS:keys.json:ro \
{image_name}:1.0

with absolute path as well:

docker run \ 
-e GOOGLE_APPLICATION_CREDENTIALS=/Users/{username}/Desktop/football-data/keys.json \
-v $GOOGLE_APPLICATION_CREDENTIALS:keys.json:ro \
{image_name}:1.0

both error out and say:

google.auth.exceptions.DefaultCredentialsError: File keys.json was not found.

I'm running this command from the directory in which the image was built and keys.json is in the pwd

Paolo
  • 21,270
  • 6
  • 38
  • 69
scarecrow
  • 29
  • 3
  • Is the value `GOOGLE_APPLICATION_CREDENTIALS` a path or "just a string"? If it is "just a string", it might be interpreted as volume name. --- I am astonished that this command does not exit with an error. I get the message `"... mount path must be absolute.`" and this is also what I would recommend. – Turing85 Jan 18 '23 at 19:47
  • @Turing85 - it's just a string. Trying to follow [this thread here](https://stackoverflow.com/questions/57137863/set-google-application-credentials-in-docker) but not sure why it can't find the file. – scarecrow Jan 18 '23 at 19:58
  • Setting `-e SOMEVAR=somevalue` on the `docker run` command line does not mean you can refer to `$SOMEVAR` elsewhere in the command line. The `-e` option sets an environment variable in the container; it doesn't set a variable in your local shell. – larsks Jan 18 '23 at 21:49
  • GOOGLE_APPLICATION_CREDENTIALS must be a path. In Addition, you can set the volume path like that: -v $GOOGLE_APPLICATION_CREDENTIALS:/key/key.json:ro – guillaume blaquiere Jan 19 '23 at 10:40

0 Answers0