I'm hosting a Docker image inside of Google Container OS on Google Compute Engine. To deploy my container, I do this:
gcloud compute instances update-container example --container-image "$IMAGE_WITH_TAG"
On my latest deployment, I got this error:
failed to register layer: Error processing tar file(exit status 1): write /usr/share/man/man1/journalctl.1.gz: no space left on device
After SSHing into my Docker container, I ran docker images and noticed that Docker was still hanging on to my old images. I can manually delete these images, but the same problem is going to occur after a few more deployments.
Is there a way I can automatically remove old Docker images while deploying to Container OS via gcloud compute instances update-container?
Currently, Compute Engine does not have a feature on cleaning up old and unused images automatically. It's not mentioned at the steps performed when updating a container on Compute Engine.
As of now, a workaround is to run the commands below to clear disks. You can also add on on your shutdown script:
Above commands will do the following:
Explanation of distinction between "dangling" and "unused" images.
This similar answer provides an example using prune command and another workaround to make sure that old images are cleared before updating the container image.