Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Best way to authenticate when testing a container in the local development environment

Hello everyone,

I'm developing a Cloud Run Job on Windows (in .NET/C#).
It is interacting with Cloud Storage so I must be authenticated.
I've set up Application Default Credentials via gcloud auth application-default login and it is running fine locally with dotnet run.

Then I containerize the code, but of course it won't run inside Docker as the application_default_credentials.json is local to the host.
So I've copied this credentials file to the build directory, and added a COPY instruction in the Dockerfile: COPY application_default_credentials.json /root/.config/gcloud/
It is running fine.

But this solution is not satisfactory:

  • I have to copy the file manually first (as COPY can't access files outside the Build Context which is the current directory)
  • This COPY instruction should be only for local build as it is not necessary once the container is run by Cloud Run in pre-production and production

Any input is welcome.

0 0 120
0 REPLIES 0