简体   繁体   中英

Using docker gcplogs (Google Cloud Logging driver) on digital ocean with docker compose

I currently have set up docker compose on digital ocean and would like to try out gcplogs (Google Cloud Logging driver). As I understand it I need to set my Google Application Default Credentials by downloading a json keyfile and setting GOOGLE_APPLICATION_CREDENTIALS to point to it.

This is how I have set this up (without it working)

version: "2"
services:
  containername: 
    build: /whatever/containername
    environment:
      - GOOGLE_APPLICATION_CREDENTIALS=/usr/src/app/project-12349aba.json
    logging:
      driver: gcplogs
      options:
        env: test
        gcp-project: my-project-name

This gives me the following error:

ERROR: for containername  Failed to initialize logging driver: google.DefaultTokenSource: google: could not find default credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.

What am I missing? What am I doing wrong?

I am positive that the credential-file works and is at that location because I use it inside the app with the ruby google/cloud gem with success. I am also capable of using that ruby-gem to log successfully, but I would really like to get this working on the docker container so I can re-use it on other non-ruby projects.

The logging driver is run by the docker daemon not the container. You need to provide those credentials to the daemon environment, what you're doing currently is providing them to the container, which as you've discovered, does not work.

To provide them to the daemon you'll need to first copy or download the json file on the Digital Ocean host. Then

export GOOGLE_APPLICATION_CREDENTIALS=...
# run the docker daemon
docker daemon ....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM