在数字海洋上使用 docker gcplogs(Google 云日志驱动程序)与 docker 组合

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

我目前已经在 digital ocean 上设置了 docker compose 并想试用 gcplogs(Google 云日志驱动程序)。据我了解,我需要通过下载 json 密钥文件并设置 GOOGLE_APPLICATION_CREDENTIALS 指向它来设置我的 Google Application Default Credentials

这就是我的设置方式(没有工作)

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-gem 成功登录,但我真的很想让它在 docker 容器上运行,这样我就可以在其他非ruby 个项目。

日志驱动程序 运行 由 docker 守护程序 而非容器。您需要向 daemon 环境提供这些凭据,您当前正在做的是将它们提供给容器,正如您所发现的,这是行不通的。

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

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