-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker-utils.sh
executable file
·73 lines (60 loc) · 1.34 KB
/
docker-utils.sh
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
# Help function
show_help() {
echo -e "
\033[1mDOCKER UTILS\033[0m
A bundle of useful docker utils.
Generic command:
./docker_utils.sh COMMAND
\033[1mCOMMANDS\033[0m:
help \t\t Show this help.
export <path> \t Export all images. By default, in actual dir.
import <path> \t Import all images. By default, in actual dir.
"
}
# Cheking the mode variable and exits if it is not set
if [ -z "$1" ]; then
show_help
exit 1
fi
if [ $1 = "export" ]; then
echo "Exporting all the images"
# Checking if the variable path exists, by default it is the actual path
if [ -z "$2" ]; then
workdir=$(pwd)
else
workdir=$2
fi
for image_id in $(docker images --format "{{.Repository}}:{{.Tag}}")
do
echo "Saving... " "$image_id"
if ! docker save "$image_id" -o "$workdir"/"$image_id";
then
echo "*** Exportation error ***"
fi
done
elif [ $1 = "import" ]; then
echo "Importing all the images"
# Checking if the variable path exists, by default it is the actual path
if [ -z "$2" ]; then
workdir=$(pwd)
else
workdir=$2
fi
# Searching all files in the workdir
for file in $workdir*
do
if [ ! -e "$file" ]
then
echo "$file no es un archivo"
else
echo "Loading... " "$file"
if ! docker load -i "$workdir"/"$file";
then
echo "*** The image $file fails"
fi
fi
done
elif [ $1 = "help" ]; then
show_help
fi