Push all the images from a local registry to DockerHub in one go
The other day, I wanted to push all the images from my local Docker registry to the Docker Hub but I didn't want to do it manually so I wrote this bash shell script:
What the script's doing basically:
1. Get all the images in the local registry, assuming the image's name is in this form:
local.registry.domain/branch/image_name:my-tag
2. For each image, create a new tag that match DockerHub's requirement which is:
docker_hub_username/my-tag
3. Then push that image into Docker Hub
Here is my Docker Hub repositories after finish the PUSH, you can have a look:
https://hub.docker.com/u/dangtrinhnt/
Profit!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# | |
# This will push all the images from a local registry to DockerHub. For example: | |
# local_registry_domain/branch/image_name:my-tag -> docker_hub_username/image_name:my-tag | |
# | |
dh_username='' | |
dh_passwd='' | |
local_repo='' | |
local_branch='' | |
local_repo_path="$local_repo/$local_branch/" | |
local_tag='' | |
docker login -u $dh_username -p $dh_passwd | |
# list local images | |
local_images=$(docker images "$local_repo_path*" --format "{{.Repository}}") | |
for i in $local_images | |
do | |
img_name=${i//$local_repo_path/''} | |
old_tag="$i:$local_tag" | |
new_tag="$dh_username/$img_name:$local_tag" | |
# tag the image to match dockerhub repo | |
docker tag $old_tag $new_tag | |
# push the image to docker | |
docker push $new_tag | |
done |
What the script's doing basically:
1. Get all the images in the local registry, assuming the image's name is in this form:
local.registry.domain/branch/image_name:my-tag
2. For each image, create a new tag that match DockerHub's requirement which is:
docker_hub_username/my-tag
3. Then push that image into Docker Hub
Here is my Docker Hub repositories after finish the PUSH, you can have a look:
https://hub.docker.com/u/dangtrinhnt/
Profit!
Comments
Post a Comment