Skip to content

Instantly share code, notes, and snippets.

@kwonghung-YIP
Created December 3, 2020 03:42
Show Gist options
  • Save kwonghung-YIP/0cfa8a37cb6394116275cd3e278a058c to your computer and use it in GitHub Desktop.
Save kwonghung-YIP/0cfa8a37cb6394116275cd3e278a058c to your computer and use it in GitHub Desktop.
[docker-CLI] Re-tag and Re-push the images that used by running containers to your private image registry
#!/bin/bash
docker login -u <<registry login>> -p <<password>> <<user registry host>>
docker ps -a --format "{{.ID}} {{.Image}}" | grep <<your registry prefix>> | \
while read line
do
ctrid=`echo $line | awk '{print $1}'`
imgtag=`echo $line | awk '{print $2}'`
imgdigest=`docker container inspect --format "{{.Config.Image}}" $ctrid`
#echo "container id : $ctrid"
#echo "image tag : $imgtag"
#echo "image digest : $imgdigest"
docker image tag $imgdigest $imgtag
docker image push $imgtag
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment