简体   繁体   English

如何在 GCP 中容器操作系统镜像的启动脚本中使用 gsutil?

[英]How to use gsutil in startup-script on container-os image in GCP?

I'm creating my GCE instance with gcloud beta compute instances create-with-container and the following startup-script:我正在使用gcloud beta compute instances create-with-container和以下启动脚本创建我的 GCE 实例:

#! /bin/bash
gsutil cp gs://artifacts.<PROJECT-ID>.appspot.com/some-file .
docker-credential-gcr configure-docker
docker pull gcr.io/<PROJECT-ID>/image:tag
docker run --name compose --rm -v $PWD:$PWD -w $PWD -v /var/run/docker.sock:/var/run/docker.sock docker/compose:1.26.0 up -d --force-recreate

but I am ending with the following:但我以以下结尾:

Jun 23 15:22:08 app startup-script[389]: INFO Found startup-script in metadata.
Jun 23 15:22:08 app startup-script[389]: INFO startup-script: /var/lib/google/startup-DqGmUt/tmpPyYsVd: line 2: gsutil: command not found
Jun 23 15:22:09 app startup-script[389]: INFO startup-script: ERROR: Unable to save docker config: mkdir /root/.docker: read-only file system

I tried installing gsutil also in the startup-script but it bails out with the same problem of /root being RO.我也尝试在启动脚本中安装 gsutil,但它解决了 /root 是 RO 的相同问题。 Is it actually possible to do this on a COS image?是否真的可以在 COS 图像上执行此操作?

As the documentation [1] it seems gsutil tool runs on Linux/Unix, MAC OS and also in windows.作为文档 [1],gsutil 工具似乎可以在 Linux/Unix、MAC OS 以及 windows 上运行。 So it seems COS image don't support gsutil.所以看起来 COS 镜像不支持 gsutil。 Also I hope link [2] and [3] could be helpful.我也希望链接 [2] 和 [3] 能有所帮助。

Please have documentation [4] as there have some limitation for COS image.请提供文档 [4],因为 COS 图像有一些限制。

[1] https://cloud.google.com/storage/docs/gsutil_install#specifications [1] https://cloud.google.com/storage/docs/gsutil_install#specifications

[2] `gsutil cp` from Storage to compute instance running container doesn't copy files [2] 从存储到计算实例运行容器的`gsutil cp`不复制文件

[3] https://github.com/GoogleCloudPlatform/gsutil/issues/453 [3] https://github.com/GoogleCloudPlatform/gsutil/issues/453

[4] https://cloud.google.com/container-optimized-os/docs/concepts/features-and-benefits#limitations [4] https://cloud.google.com/container-optimized-os/docs/concepts/features-and-benefits#limitations

There is a way to use tools like gsutil and gcloud in a Container Optimized OS .有一种方法可以在Container Optimized OS中使用gsutil 和 gcloud等工具。 You can access the toolbox to use gsutil to access buckets and then copy the downloaded data form the toolbox directory to your actual VM.您可以访问工具箱以使用 gsutil 访问存储桶,然后将下载的数据从工具箱目录复制到您的实际 VM。

As soon as you started the toolbox you can exchange files between the toolbox and your vm with either /var/lib/toolbox/USER-gcr.io_google-containers_toolbox-20200404-00/ to get data from the toolbox while in your vm or /media/root/ while in the toolbox to get files from the vm.启动工具箱后,您可以使用/var/lib/toolbox/USER-gcr.io_google-containers_toolbox-20200404-00/在工具箱和虚拟机之间交换文件,以便在虚拟机中从工具箱中获取数据或/media/root/ while 在工具箱中以从 vm 获取文件。

More information https://cloud.google.com/container-optimized-os/docs/how-to/toolbox更多信息https://cloud.google.com/container-optimized-os/docs/how-to/toolbox

For gcloud beta compute instances create with --create-disk=...image=projects/cos-cloud/global/images/cos-85-13310-1416-9,... , I used a containerized gsutil in the startup script:对于使用--create-disk=...image=projects/cos-cloud/global/images/cos-85-13310-1416-9,... gcloud beta compute instances create ,我在启动时使用了容器化的gsutil脚本:

#!/bin/bash
docker run -v /tmp:/tmp google/cloud-sdk:slim gsutil cp gs://BUCKET/file /tmp/
cat /tmp/file

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM