注意:以下的所有操作都是建立在私有仓库搭建好的基础之上!(查看资料)
创建脚本
vim push.sh
编辑脚本内容
#!/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
创建上传所有镜像的脚本
vim pushall.sh
编辑该脚本的内容
#!/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
创建下拉指定镜像的脚本
vim pull.sh
编辑该脚本的内容
#!/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
给三个脚本可执行的权限
chmod +x ./push.sh ./pushall.sh ./pull.sh
执行脚本
# 上传指定镜像(可上传多个,中间用空格隔开)
./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
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。