我无法验证Docker的google云驱动程序gcplogs,尽管我已将env var GOOGLE_APPLICATION_CREDENTIALS设置为我的服务帐户的JSON凭据所在的路径/文件.错误消息如下:
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
最佳答案
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
有用的链接:
> https://cloud.google.com/docs/authentication/getting-started
> https://docs.docker.com/config/daemon/systemd
> https://docs.docker.com/config/containers/logging/gcplogs/