在Docker上使用Docker gcplogs(Google Cloud Logging driver)在数字海洋上撰写

我目前已经build立了数字海洋的docker工具,并且想要尝试gcplogs(Google Cloud Logging driver)。 据我了解,我需要通过下载一个json密钥文件并设置GOOGLE_APPLICATION_CREDENTIALS指向它来设置我的Google应用程序默认凭证 。

这是我设置了这个(没有工作)

 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 

这给了我以下错误:

 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. 

我错过了什么? 我究竟做错了什么?

我认为这个凭证文件是有效的,因为我在应用程序里面使用了ruby google/cloud gem成功。 我也能够使用这个ruby成功地login,但我真的想在Docker容器上得到这个工作,所以我可以在其他非Ruby项目上重新使用它。

日志驱动程序由docker守护程序而不是容器运行。 您需要将这些凭证提供给守护进程环境,您当前正在做的是将它们提供给容器,正如您发现的那样,该容器不起作用。

要将它们提供给守护程序,您需要先在Digital Ocean主机上复制或下载json文件。 然后

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