7

gcplogs尽管我已将 env var 设置GOOGLE_APPLICATION_CREDENTIALS为我的服务帐户的 JSON 凭据所在的路径/文件,但我无法验证 Docker 的谷歌云驱动程序。错误消息如下:

ERROR: for oncrm_oncrm_1  Cannot start service oncrm: 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.

我在 docker-compose 上使用的配置是:

logging:
      driver: gcplogs
      options:
        gcp-project: "gcloud-project-id"
        gcp-meta-name: "prod-helpsec-01"
        labels: "app"

我试图运行 docker 容器的环境是:

  • docker-ce v18.03
  • docker-compose v1.21.0
  • Ubuntu 17.10
4

1 回答 1

7
google.DefaultTokenSource: google: could not find default credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.

当我使用gcplogs日志驱动程序运行 docker 服务时,我遇到了与上述相同的问题。

这是我的问题解决方案:

在主机上:

sudo mkdir -p /etc/systemd/system/docker.service.d

创建文件:

/etc/systemd/system/docker.service.d/docker-service-override.conf

包含以下内容:

[Service]
Environment="GOOGLE_APPLICATION_CREDENTIALS=/root/gcp-logging-service-cridentials.json"

重启docker服务:

sudo systemctl daemon-reload
sudo systemctl restart docker

有用的链接:

  1. https://cloud.google.com/docs/authentication/getting-started
  2. https://docs.docker.com/config/daemon/systemd
  3. https://docs.docker.com/config/containers/logging/gcplogs/
于 2018-07-16T08:48:37.977 回答