批量上传镜像到私有仓库

注意:以下的所有操作都是建立在私有仓库搭建好的基础之上!(查看资料)

  1. 创建脚本
vim push.sh
  1. 编辑脚本内容
# !/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 && exitecho_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
  1. 创建上传所有镜像的脚本
vim pushall.sh
  1. 编辑该脚本的内容
# !/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-26for image in `sudo docker images|grep -v "REPOSITORY"|grep -v ""|awk '{print $1":"$2}'` do    ./push.sh $imagedone
  1. 创建下拉指定镜像的脚本
vim pull.sh
  1. 编辑该脚本的内容
# !/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 intoregistry=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 && exitecho_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
  1. 给三个脚本可执行的权限
chmod +x ./push.sh ./pushall.sh ./pull.sh
  1. 执行脚本
# 上传指定镜像(可上传多个,中间用空格隔开)./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

关键字:产品经理

版权声明

本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处。如若内容有涉嫌抄袭侵权/违法违规/事实不符,请点击 举报 进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部