-
Notifications
You must be signed in to change notification settings - Fork 1
/
dump-images.sh
executable file
·35 lines (31 loc) · 944 Bytes
/
dump-images.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
#!/bin/bash
####################################################################
# Docker Images dumpers
# - Code by Jioh L. Jung
####################################################################
#- Move Script directory as base
BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd "${BASE_DIR}"
#- Go to target Directory
if [[ ! -z "$1" ]]; then
echo "> Change DIR to $1"
mkdir -p "$1"
cd "$1"
fi
for j in $(docker images | tail -n +2 | awk '{printf "%s:%s\n", $1, $2}')
do
FN="$(echo "$j" | tr '[/]' '_' | tr '[:]' '+').tgz"
if [ -f "${FN}" ]; then
echo ">> File Existed: ${FN}"
if [ "${FN: -10}" == "latest.tgz" ]; then
echo ">> Overwrite (latest tag)"
echo "> ${j} Saving -> ${FN}.."
docker save ${j} | gzip -c > ${FN}
echo "> ${j} Done.."
fi
else
echo "> ${j} Saving -> ${FN}.."
docker save ${j} | gzip -c > ${FN}
echo "> ${j} Done.."
fi
done