Docker Google gsutil auth不带提示

Docker Google gsutil auth不带提示,docker,gcloud,gsutil,Docker,Gcloud,Gsutil,我想在Docker容器中使用gsutil。我已经创建了一个O2Auth服务帐户JSON文件 如何设置gsutil auth以使用JSON配置文件并在没有提示的情况下执行命令 目前,我得到了如下结果: $ gsutil config -e It looks like you are trying to run "/.../google-cloud-sdk/bin/bootstrapping/gsutil.py config". The "config" command is no longer n

我想在Docker容器中使用gsutil。我已经创建了一个O2Auth服务帐户JSON文件

如何设置gsutil auth以使用JSON配置文件并在没有提示的情况下执行命令

目前,我得到了如下结果:

$ gsutil config -e
It looks like you are trying to run "/.../google-cloud-sdk/bin/bootstrapping/gsutil.py config".
The "config" command is no longer needed with the Cloud SDK.
To authenticate, run: gcloud auth login
Really run this command? (y/N) y
This command will create a boto config file at /.../.boto
containing your credentials, based on your responses to the following questions. 
What is the full path to your private key file? 

我必须使用什么命令/参数/设置来设置提示?

通过执行以下命令解决了此问题:

gcloud auth activate-service-account --key-file=/opt/gcloud/auth.json

整个示例和完成的容器都可以在这里找到:

如果您只需要gsutil并绕过提示,则可以使用expect脚本轻松完成:

#!/usr/bin/expect
spawn gsutil config -e
expect "What is the full path to your private key file?" { send "/path/your.key\r" }
expect "Would you like gsutil to change the file permissions for you? (y/N)" { send "y\r" }
expect "What is your project-id?" { send "your-projet-42\r" }
interact
仅使用gsutil:

首先运行此命令以手动配置身份验证

gsutil config -a
这将创建具有所需凭据的/root/.boto文件。 将该路径/文件复制到docker映像中


gsutil现在将使用这些凭据。

-o凭据:gs\u service\u key\u文件=使用boto配置覆盖参数(如中所述)起到了很好的作用


有没有办法用env vars而不是json文件进行身份验证?
$ gsutil -v
gsutil version: 4.57
$ gsutil -o Credentials:gs_service_key_file=key.json ls -al gs://bucket/filename
79948  2021-05-24T02:12:25Z  gs://bucket/filename#1111111145678393  metageneration=2