0

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.

Automatico
  • 12,420
  • 9
  • 82
  • 110

1 Answers1

2

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 ....
dnephin
  • 25,944
  • 9
  • 55
  • 45
  • Thanks! But then, the loggers are useless. The point of docker, as I understand it, is to have disposable servers and containers so that I can spawn one up instantly and not think about any of the config. Is there a way to bake this into docker-compose? Or is that also just affecting containers? – Automatico Sep 17 '16 at 20:00
  • docker-compose is only for configuring containers. You set the driver you want to use from the Compose file, but the Docker Engine needs to know how to use that driver. I don't think that makes the loggers useless, it just means you have to configure the Engine properly first. – dnephin Sep 18 '16 at 14:25
  • "Useless" might have been an overstatement on my part, but still, it reduces the usability. You do indeed set the loggers per-container, so it makes sense to me to have them be configurable per container as well. – Automatico Sep 24 '16 at 18:23