0

In my ~/.bashrc, I have set GOOGLE_APPLICATION_CREDENTIALS=~/.gc/credential_file_name.json.

My source code is located in (and I'm working from here) ~/repos/github_repo/ where I have a Dockerfile with its working directory set to /usr/src/app.

If I copy ~/.gc/credential_file_name.json to ~/repos/github_repo/credential_file_name.json and run the docker container with

docker run -t \
    -e GOOGLE_APPLICATION_CREDENTIALS=/usr/src/app/credential_file_name.json \
    ...

the credential file gets picked up and subsequent code runs ok.

But, ideally, I don't want to copy the credential to my github repository, as that risks possibly pushing it on github (even when I add it to .gitignore, it's still not safe).

Additionally, instead of having to explicitly give then full path -e GOOGLE_APPLICATION_CREDENTIALS=/usr/src/app/credential_file_name.json, I would like to do something like -e GOOGLE_APPLICATION_CREDENTIALS=${GOOGLE_APPLICATION_CREDENTIALS} where ${GOOGLE_APPLICATION_CREDENTIALS} gets picked up from my ~/.bashrc.

But obviously, ${GOOGLE_APPLICATION_CREDENTIALS} will point to a path on my computer, which different directory structure than the docker container.

What is the best way to resolve this? I'm new to this and I came across direnv and .envrc, but don't quite understand.

I'm using Makefile to run the docker commands. I will try to avoid docker-compose, but if it solves this problem, please let me know.

Thanks for help!

chesslad
  • 31
  • 3
  • `${GOOGLE_APPLICATION_CREDENTIALS} will point to a path on my computer` Great, so now you can `-v ${GOOGLE_APPLICATION_CREDENTIALS}:${GOOGLE_APPLICATION_CREDENTIALS}:ro` – KamilCuk Jan 15 '23 at 11:07
  • [Docker and securing passwords](https://stackoverflow.com/questions/22651647/docker-and-securing-passwords) may have some relevant advice. The host and container paths don't have to match, and one legitimate option is to mount the file to a fixed container path. – David Maze Jan 15 '23 at 11:32
  • @KamilCuk great, thank you this solved it. If you post an answer, I will accept it as the best. – chesslad Jan 15 '23 at 12:39

0 Answers0