How do I put application_default_credentials.json from Google cloud to Docker-compose

Hello,

I’m new to docker-compose. I’m learning to run Airflow using docker-compose. I’m trying to connect to my google cloud. However, when I trigger DAG, I found an error message raise exceptions.DefaultCredentialsError(
google.auth.exceptions.DefaultCredentialsError: File application_default_credentials.json was not found.

I have tried several attempts by putting application_default_credentials.json file in the dags folder, config folder but I still get an error. After googling about this error, I think I need to mount the application_default_credentials.json to docker.

Does anybody can help me with this?

Thanks

Check the Docker compose docs for volumes, probably use a “bind mount”.

hi @bluepuma77,

Thanks for replying my question above.
Did you mean that I need to adjust the docker-compose.yaml file by adding another image and with type: bind, and write source and target pointing to application_default_credentials.json ?

You application is trying to access a file. So you need to ensure it’s there (inside the container) and readable.

Usually you would use a bind mount to mount the file from host into the container to the right folder.

services:
  myservice:
    volumes:
      - /home/app/creds.json:/path/inside/container/application_default_credentials.json:ro

Or you can use a config element to create the file within compose itself (example, at bottom).