Docker Image Housekeeping after CICD Image Building and Pushing

Hello Community,

Currently I’m building images in a gitlab-cicd pipeline by a bash script and push these fresh builded images to our internal repository. So far so good.

Is there a way to remove these images automatically after a successful push from local storage also with a bash command?

Here is an example snippet from our cicd build pipeline script:

docker login -u $CI_DOCKER_HARBOR_REGISTRY_USERNAME -p $CI_DOCKER_HARBOR_REGISTRY_PASSWD $CI_DOCKER_HARBOR_REGISTRY_SERVER > /dev/null 2>&1
docker build --force-rm --no-cache -t $strImageStringHarbor -f $objDockerFileNames .
docker push $strImageStringHarbor

### ---> CNDS dmz/public SECTION FOR RETAG AND PUSH <--- ###
docker logout
docker login -u $CI_DOCKER_OTHER_REGISTRY_USERNAME -p $CI_DOCKER_OTHER_REGISTRY_PASSWD $CI_DOCKER_OTHER_REGISTRY_SERVER > /dev/null 2>&1
docker tag $strImageStringHarbor $strImageStringOTHERdmz
docker push $strImageStringOTHERdmz

### -> HERE REMOVE / HOUSEKEEPING OF IMAGE FROM "docker push $strImageStringOTHERdmz" AND "docker push $strImageStringHarbor"

Cheers

I think

docker rmi "$strImageStringHarbor" after the push should take care of it. once other way is using

docker system prune to clear our all the dangling layers.