blob: 45ac27402720b6a25e26a5f6edb2ec304298fc2c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#!/bin/bash
for i in "$@"
do
case $i in
-n=*|--name=*)
NAME="${i#*=}"
shift
;;
-v=*|--version=*)
VERSION="${i#*=}"
shift
;;
-d=*|--dir=*)
DIR="${i#*=}"
shift
;;
esac
done
if [[ ${NAME} && ${VERSION} && ${DIR} ]]; then
echo "assign the x to all files and dirs under current dir.."
chmod +x -R .
echo "begin to build image ${NAME}.."
docker build --no-cache -t ${NAME}:${VERSION} . >/dev/null || { echo -e "\nBuild docker image failed!";exit 1; }
docker rmi $(docker images | grep "^<none>" | awk '{print $3}') &>/dev/null
# docker save -o ${NAME}.tar ${NAME}:${VERSION} >/dev/null || { rm -f ${NAME}.tar &>/dev/null;echo -e "\nSave docker image failed!";exit 1; }
if [ ! -d ${DIR} ]; then
mkdir -p ${DIR}
fi
mv ${NAME}.tar ${DIR}/${NAME}.tar &>/dev/null
echo "build completes!"
else
echo "not all -n and -v and -d are provided!"
exit 1
fi
|