1 Star 0 Fork 10

QMGPS/dev-env-ubuntu

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
save-image-ubuntu-dev.sh 2.33 KB
一键复制 编辑 原始数据 按行查看 历史
kang 提交于 2021-10-29 20:31 . support 16.04&18.04
#/bin/bash
set -e
# -------------------------------------------------------------------------------
# Filename: save-image-ubuntu-dev.sh
# UpdateDate: 2021/07/26
# Description: 1. commit: 提交容器到镜像,实现容器持久化;
# 2. save: 导出镜像文件,实现镜像内容持久化。
# Example:
# ./save-image-ubuntu-dev.sh
# ./save-image-ubuntu-dev.sh 16.04
# ./save-image-ubuntu-dev.sh 18.04
# Depends:
# Notes:
# -------------------------------------------------------------------------------
#CMD_TIME=$(date +%Y%m%d%H%M%S.%N) # eg:20210402230402.403666251
CMD_TIME=$(date +%Y%m%d%H%M%S) # eg:20210402230402
#Dockerfile(16.04/18.04/CentOS)
OSVer="16.04"
if [[ $# -ne 0 ]];then OSVer="${1}";fi
# Source env
source ./env.sh $OSVer
#New Docker image name
NAME_IMAGE_NEW="$MY_IMAGE:$VERSION-$CMD_TIME"
FILENAME_IMAGE_NEW="image-$OS-$PATH_WORK-$VERSION-$CMD_TIME.tar.gz"
# 2.commit docker container
echo -e "${green}[# Docker images: ${none}"
sudo docker images | grep ${MY_IMAGE}
num_images=`sudo docker images | grep ${MY_IMAGE} | grep $VERSION-$CMD_TIME | awk '{print $3}'`
if [ $num_images ];then
echo -e "${green}[# Save docker image: ${none}"
sudo docker save -o $FILENAME_IMAGE_NEW $NAME_IMAGE_NEW
ls -lh $FILENAME_IMAGE_NEW
echo -e "${green} Completed!${none}" && exit 0
else
echo -e "${green} Images does not exist!${none}"
echo -e "${green}[# Docker container: ${none}"
sudo docker ps -a | grep ${MY_CONTAINER}
num_container=`sudo docker ps -a | grep ${MY_CONTAINER} | awk '{print $1}'`
if [ $num_container ];then
echo -e "${green}[# Commit docker container: ${none}"
sudo docker commit $num_container $NAME_IMAGE_NEW
echo -e "${green} Completed!${none}"
else
echo -e "${red} Container does not exist!${none}" && exit -1
fi
fi
# 3.save docker image
echo -e "${green}[# Docker images: ${none}"
sudo docker images | grep ${MY_IMAGE}
num_images=`sudo docker images | grep ${MY_IMAGE} | grep $VERSION-$CMD_TIME | awk '{print $3}'`
if [ $num_images ];then
echo -e "${green}[# Save docker image: ${none}"
sudo docker save -o $FILENAME_IMAGE_NEW $NAME_IMAGE_NEW
ls -lh $FILENAME_IMAGE_NEW
echo -e "${green} Completed!${none}"
else
echo -e "${red} Images does not exist!${none}" && exit -1
fi
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/qmgps/dev-env-ubuntu.git
git@gitee.com:qmgps/dev-env-ubuntu.git
qmgps
dev-env-ubuntu
dev-env-ubuntu
master

搜索帮助