Reputation: 9085
When I push a new image that overwrites an existing image (same name and tag), the previous image is just being expunged from its tag and remains in the repository.
Is there a way to configure gcr
or my docker commands to just not keep the expired images? I could query images without tag and delete them manually, but it seems absurd.
My code to push images:
export GCLOUD_PROJECT="..."
gcloud auth activate-service-account --key-file gcloud-api-key.json
gcloud config set project $GCLOUD_PROJECT
gcloud auth configure-docker --quiet
docker build -t my_image .
docker tag my_image asia.gcr.io/$GCLOUD_PROJECT/my_image:dev
docker push asia.gcr.io/$GCLOUD_PROJECT/my_image:dev
Upvotes: 1
Views: 1281
Reputation: 45
Unfortunately there is no automatic deletion from GCR when you push a new docker image with the same tag. On the other hand google provides the API to automate it and you can change your script as following by adding the delete command:
export GCLOUD_PROJECT="..."
gcloud auth activate-service-account --key-file gcloud-api-key.json
gcloud config set project $GCLOUD_PROJECT
gcloud auth configure-docker --quiet
docker build -t my_image .
docker tag my_image asia.gcr.io/$GCLOUD_PROJECT/my_image:dev
# here delete the image
gcloud container images delete asia.gcr.io/$GCLOUD_PROJECT/my_image:dev
# now push the new one
docker push asia.gcr.io/$GCLOUD_PROJECT/my_image:dev
You can find better information in the google GCR documentation https://cloud.google.com/container-registry/docs/managing#deleting_images.
Upvotes: 1