Skip to content

Instantly share code, notes, and snippets.

@denniskupec
Last active March 7, 2020 21:58
Show Gist options
  • Save denniskupec/08c9ce15e8f8d8472adae69e95407e4e to your computer and use it in GitHub Desktop.
Save denniskupec/08c9ce15e8f8d8472adae69e95407e4e to your computer and use it in GitHub Desktop.
Tag and push all local Docker images to a private registry
#!/bin/sh -e
# alias docker="docker.exe"
registry="registry.local:5000"
# list registry contents:
# curl -s "https://${registry}/v2/_catalog" | jq
for img in $(docker image ls | awk 'NR>1{ print $3; }')
do
[ "${img}" = "" ] || [ "${img}" = "<none>" ] && continue
fullname=$(docker image inspect --format='{{ index (.RepoTags) 0 | printf "%s" }}' ${img})
if [ $(echo "${fullname}" | grep "${registry}") ]; then
echo "${img} already tagged" && continue
fi
docker image tag ${fullname} ${registry}/${fullname}
docker image push ${registry}/${fullname}
docker image rm ${fullname}
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment