简体   繁体   English

谷歌云计算实例更新

[英]Google cloud compute instance update

I have a website deployed using docker image inside google compute instance.我在谷歌计算实例中使用 docker 图像部署了一个网站。

I'm unable to update the google cloud instance with a new image.我无法使用新图像更新谷歌云实例。 Updating the compute instance with new docker image and running the container changes nothing.使用新的 docker 映像更新计算实例并运行容器不会改变任何内容。

Here are the steps I take to update the google compute instance:以下是我更新谷歌计算实例的步骤:

docker build -t vue_app -f deploy/web/Dockerfile . --tag gcr.io/namesapi-1581010760883/vue-app:v1
docker push gcr.io/namesapi-1581010760883/vue-app:v1
gcloud compute instances update-container --container-image=gcr.io/namesapi-1581010760883/vue-app:v1 vue-app-vm

So in the first line I build the image containing the website and http-server.因此,在第一行中,我构建了包含网站和 http-server 的图像。 I ran it locally and can confirm the image is working and contains all the changes I expect.我在本地运行它,可以确认图像正常工作并包含我期望的所有更改。

Next line is pushing the image to google cloud and the final third line is supposed to update an existing google compute instance with the new image.下一行是将图像推送到谷歌云,最后第三行应该用新图像更新现有的谷歌计算实例。

After running this none of the changes are reflected in the instance.运行此操作后,实例中不会反映任何更改。 I visit the website hosted on the instance and see that nothing has changed.我访问了实例上托管的网站,发现没有任何变化。 I've done these same steps many times and it all worked fine up until recently.我已经多次执行这些相同的步骤,直到最近它都运行良好。 What am I missing?我错过了什么?

Solved the issue.解决了这个问题。 For future reference running the following以供将来参考运行以下

gcloud compute instances update-container --container-image=gcr.io/namesapi-1581010760883/vue-app:v1 vue-app-vm

does not replace the existing image on the instance, instead it creates a new image.不会替换实例上的现有图像,而是创建一个新图像。 So after some time the instance accumulate a number of images:所以一段时间后,实例积累了许多图像:

REPOSITORY                                            TAG                 IMAGE ID            CREATED             SIZE
gcr.io/namesapi-1581010760883/vue-app                 v1                  d21bd8939323        9 days ago          394MB
gcr.io/namesapi-1581010760883/vue-app                 <none>              c136b1c9e0d4        13 days ago         387MB
gcr.io/namesapi-1581010760883/vue-app                 <none>              b1b11f2c9678        4 weeks ago         385MB
gcr.io/namesapi-1581010760883/vue-app                 <none>              a5ef94db2438        4 weeks ago         385MB
gcr.io/namesapi-1581010760883/vue-app                 <none>              23b52253c060        6 weeks ago         385MB
gcr.io/namesapi-1581010760883/vue-app                 <none>              cb03925836a7        2 months ago        384MB
gcr.io/gce-containers/konlet                          v.0.9-latest        da64965a2b28        19 months ago       73.4MB
gcr.io/stackdriver-agents/stackdriver-logging-agent   0.2-1.5.33-1-1      fcfafd404600        22 months ago       548MB

I think what happened in my case was the compute instance ran out of disk space and new image was not pushed when running the above command.我认为在我的情况下发生的情况是计算实例的磁盘空间不足,并且在运行上述命令时没有推送新图像。 Google cloud API did not raise a warning or anything, which is why this was tricky to understand.谷歌云 API 没有发出警告或任何东西,这就是为什么这很难理解。

Solved this by logging into the instance manually and removing old images, then repeating the steps in the original question.通过手动登录实例并删除旧图像,然后重复原始问题中的步骤来解决此问题。

Thanks @RaidasGrisk !谢谢@RaidasGrisk!

This problem is insane这个问题很牛逼

You can create your instance with a startup-script which will clean your unused docker images:您可以使用启动脚本创建您的实例,该脚本将清理您未使用的 docker 图像:

gcloud compute instances create-with-container my-instance \
  --machine-type f1-micro \
  --metadata startup-script='#! /bin/bash
# Clear old Docker images
docker image prune -af' \
  --zone us-central1-a \
  --container-image gcr.io/my-project/my-image

Also, you can remove unused Docker images from your own machine with gcloud client:此外,您可以使用 gcloud 客户端从您自己的机器上删除未使用的 Docker 图像:

# Only the first time
gcloud compute config-ssh 

gcloud compute ssh --verbosity=debug my-instance --command "docker image prune -af"

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

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