注意:如下的全部操做都是创建在私有仓库搭建好的基础之上!(查看资料)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