4

I have a website deployed using docker image inside google compute instance.

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.

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. 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?

RaidasGrisk
  • 444
  • 2
  • 12

2 Answers2

7

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.

Solved this by logging into the instance manually and removing old images, then repeating the steps in the original question.

RaidasGrisk
  • 444
  • 2
  • 12
4

Thanks @RaidasGrisk !

This problem is insane

You can create your instance with a startup-script which will clean your unused docker images :

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 :

# Only the first time
gcloud compute config-ssh 

gcloud compute ssh --verbosity=debug my-instance --command "docker image prune -af"
Steve
  • 533
  • 3
  • 7
  • What happens when you prune "unused" images in the startup script? At startup time, no containers are running, so the script will delete all images, and then GCE will reinstall everything from scratch? – kennysong Feb 24 '21 at 03:14
  • @kennysong No, when the startup-script is called, your container is already running – Steve Mar 03 '21 at 10:48