0

We are using instance group to run docker containers, and set up the instance template to use image as

us.gcr.io/my-project/my-image:latest.

When we make any change to the docker image, we label it with latest and run:

gcloud compute instance-groups managed rolling-action restart my-instance-group --region us-central1.

This was working fine for the initial changes to the image, the instance group vms will pull new images and override previous images. But after more changes were made, it starts to give the error:

no space left on device

Essentially, GCP does not handle stale images, it will store the old image copy. But in the case of "rolling update to container-optimized vms", can we get a better automation handling for these use cases? We really don't want to ssh into the host and run docker image prune -a every so often manually.

1
  • I think an option to the rolling-action restart command to prune old images automatically will be ideal.
    – Jasper Wu
    Sep 6, 2019 at 23:04

1 Answer 1

3

You can add this line at the start of your startup-script [1].

docker image prune -a

This will remove all unused images before pulling a new image later in your startup-script. Please note, a restart is needed to trigger the startup-script.

Your hard drives will not fill up as a result and your VMs will have the latest docker image running on them.

[1] https://cloud.google.com/compute/docs/startupscript

1
  • I think you want docker image prune -af in the startup script, which will delete without confirmation.
    – kennysong
    Feb 24, 2021 at 3:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .