Skip to content

Instantly share code, notes, and snippets.

@ipolyzos
Last active March 28, 2020 00:29
Show Gist options
  • Save ipolyzos/b665115b53d0c4a405a02e0d8c47ad19 to your computer and use it in GitHub Desktop.
Save ipolyzos/b665115b53d0c4a405a02e0d8c47ad19 to your computer and use it in GitHub Desktop.
A simple bash script to transfer docker images between container registries.
#!/bin/bash
# MIT License
#
# Copyright (c) 2020 Ioannis Polyzos
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# Docker Image Transfer (DIT) Helper
#
# Description:
# A simple bash helper script to transfer docker images between container registries.
#
# NOTE:
# Before using this script you should have logged in the container registries.
#
# Author: Ioannis Polyzos
unset DOCKER_FROM DOCKER_TO DOCKER_IMAGE DOCKER_IMAGE_VERSION
# parse arguments
while (( "$#" )); do
case "$1" in
-h|--help)
echo "dit.sh : Docker Images Transfer (DIT) Helper aim to trasfer/copy docker images between registries."
echo "Usage: ./dit.sh --from [SOURCE REPO] --to [DEST_REPO] --image [IMAGE] --version [VERSION]"
echo "options: "
echo " -f, --from Source repository."
echo " -t, --to Destination repository. "
echo " -i, --image The image to transfer."
echo " -v, --version The version of the image to transfer."
echo " -h, --help Display this help message."
exit 0
;;
-f | --from)
DOCKER_FROM=$2
shift 2
;;
-t|--to)
DOCKER_TO=$2
shift 2
;;
-i|--image)
DOCKER_IMAGE=$2
shift 2
;;
-v|--version)
DOCKER_IMAGE_VERSION=$2
shift 2
;;
*)
echo "Invalid Option: $1" 1>&2
echo "use --help or -h for more."
exit -1
;;
esac
done
# Download original image from the source repo
docker pull ${DOCKER_FROM}/${DOCKER_IMAGE}:${DOCKER_IMAGE_VERSION}
# Tag image for transfer to the destinatio repo
docker tag ${DOCKER_FROM}/${DOCKER_IMAGE}:${DOCKER_IMAGE_VERSION} ${DOCKER_TO}/${DOCKER_IMAGE}:${DOCKER_IMAGE_VERSION}
# Push (upload) to the destination repo
docker push ${DOCKER_TO}/${DOCKER_IMAGE}:${DOCKER_IMAGE_VERSION}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment