stkvtflw
stkvtflw

Reputation: 13577

Why container-optimized compute instance uses cached image instead of the latest one?

I'm running a container-optimized compute instance with this startup-script:

#!/bin/bash

mkdir /home/my-app
cd /home/my-app
export HOME=/home/my-app

docker-credential-gcr configure-docker


docker run --rm --security-opt seccomp=./config.json gcr.io/my-project/my-app:latest

This scripts works well when creating a new instance. But when I restart an existing instance it doesnt't pull the latest image.

I've tried to delete all images from the gcr, the instance was able to start anyways, which proves that it doesn't even try to pull the latest image from gcr.

Also, for some reason startup-script logs are not showing up in Cloud Logger.

Upvotes: 2

Views: 261

Answers (1)

Mahboob
Mahboob

Reputation: 1965

As per kubernetes, With Docker, if the image already exists, the pull attempt is fast because all image layers are cached and no image download is needed.

As a workaround you can add step 1 and 2 in to your script:

1- docker images // will show you the list of images including (gcr.io/my-project/my-app:latest)

2- docker rmi --force gcr.io/my-project/my-app:latest // will delete local image

3- docker run (rest of your command, it will download the latest image again from the gcr.io)

Upvotes: 2

Related Questions