注意:如下的全部操做都是創建在私有倉庫搭建好的基礎之上!(查看資料)html
建立腳本git
vim push.sh
編輯腳本內容github
#!/bin/bash # This script will upload the given local images to a registry server ($registry is the default value). # Usage: push_images image1 [image2...] # Author: Mongo # Create: 2016-05-26 #The registry server address where you want push the images into(Please instead of your private registry's domain name) registry=willem.top:6666 ### DO NOT MODIFY THE FOLLOWING PART, UNLESS YOU KNOW WHAT IT MEANS. YOU CAN ALSO LEARN IT FROM HERE.### echo_g () { [ $# -ne 1 ] && return 0 echo -e "\033[32m$1\033[0m" } echo_b () { [ $# -ne 1 ] && return 0 echo -e "\033[34m$1\033[0m" } usage() { sudo docker images echo "Usage: $0 registry1:tag1 [registry2:tag2...]" } [ $# -lt 1 ] && usage && exit echo_b "The registry server is $registry" for image in "$@" do echo_b "Uploading $image..." sudo docker tag $image $registry/$image sudo docker push $registry/$image sudo docker rmi $registry/$image echo_g "Push $image success!" done
建立上傳全部鏡像的腳本docker
vim pushall.sh
編輯該腳本的內容vim
#!/bin/sh # This script will upload all local images to a registry server ($registry is the default value). # Usage: push_all # Author: Mongo # Create: 2016-05-26 for image in `sudo docker images|grep -v "REPOSITORY"|grep -v "<none>"|awk '{print $1":"$2}'` do ./push.sh $image done
建立下拉指定鏡像的腳本bash
vim pull.sh
編輯該腳本的內容dom
#!/bin/bash # This script will upload the given local images to a registry server ($registry is the default value). # Usage: push_images image1 [image2...] # Author: Mongo # Create: 2014-05-26 #The registry server address where you want push the images into registry=willem.top:6666 ### DO NOT MODIFY THE FOLLOWING PART, UNLESS YOU KNOW WHAT IT MEANS ### echo_g () { [ $# -ne 1 ] && return 0 echo -e "\033[32m$1\033[0m" } echo_b () { [ $# -ne 1 ] && return 0 echo -e "\033[34m$1\033[0m" } usage() { sudo docker images echo "Usage: $0 registry1:tag1 [registry2:tag2...]" } [ $# -lt 1 ] && usage && exit echo_b "The registry server is $registry" for image in "$@" do echo_b "Downloading $image..." sudo docker pull $registry/$image sudo docker tag $registry/$image $image sudo docker rmi $registry/$image echo_g "Download $image Success!" done
給三個腳本可執行的權限code
chmod +x ./push.sh ./pushall.sh ./pull.sh
執行腳本server
# 上傳指定鏡像(可上傳多個,中間用空格隔開) ./push.sh ImageName[:TagName] [ImageName[:TagName] ···] # 例如:./push.sh busybox:latest ubutnu:14.04 # 上傳全部鏡像 ./pushall.sh # 下載指定鏡像(可上傳多個,中間用空格隔開) ./pull.sh ImageName[:TagName] [ImageName[:TagName] ···] # 例如:./pull.sh busybox:latest ubutnu:14.04