如何从 Cloud 运行 容器中的 Cloud Storage 下载文件?

How to download file from Cloud Storage inside Cloud Run container?

我想在我的云 运行 容器启动时从云存储下载文件。我已经修改了 dockerfile 以添加以下命令:

CMD curl -L -o - application.yml "gs://mybucket/application.yml" ;

不幸的是,curl 似乎不支持 gs: 协议,所以这就是我遇到的错误。

curl: (6) Could not resolve host: application.yml
curl: (1) Protocol "gs" not supported or disabled in libcurl

如何实现?
根据 Cloud Run Docs,只要云 运行 和云存储在同一个 google 云项目中,我就不需要担心身份验证。我在这里错过了什么?这感觉像是一个非常基本的要求。

只用curl就可以下载,这里有例子:

https://cloud.google.com/storage/docs/downloading-objects#download-object-xml https://cloud.google.com/storage/docs/downloading-objects#download-object-json

因为您碰巧“知道”您在云 运行 实例中,您应该能够仅使用 curl 通过元数据服务获取访问令牌 在 http://metadata.google.internal 端点。此处有更多详细信息:

https://cloud.google.com/compute/docs/storing-retrieving-metadata#default

很可能您想要的密钥是 service-accounts/default/token,但也许您需要将 default 替换为您正在使用的任何服务帐户的电子邮件。

PS:您引用的云 运行 文档说:

You do not need to provide credentials manually inside Cloud Run (fully managed) container instances when using the Google Cloud client libraries. (emphasis mine)