使用docker gcplogs(Google Cloud Logging驱动程序)在数字海洋上使用docker撰写

时间:2016-09-16 12:14:23

标签: docker docker-compose digital-ocean google-cloud-logging

我目前在数字海洋上设置了docker compose,并想尝试gcplogs(Google Cloud Logging驱动程序)。据我了解,我需要通过下载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项目上重用它。

1 个答案:

答案 0 :(得分:2)

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

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

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