-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexport_image.sh
More file actions
executable file
·44 lines (33 loc) · 955 Bytes
/
export_image.sh
File metadata and controls
executable file
·44 lines (33 loc) · 955 Bytes
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
#!/bin/bash
set -eE
image="$1"
outdir="$2"
make_uuid()
{
# Usage: make_uuid
#
# generate a UUID according to RFC 4122
#
local uuid
#uuid_ref="$(cat /proc/sys/kernel/random/uuid)" # a little slower and maybe perm issues?
uuid="$(printf "%04x%04x-%04x-%04x-%04x-%04x%04x%04x" \
$RANDOM $RANDOM \
$RANDOM \
$((RANDOM & 0x0fff | 0x4000)) \
$((RANDOM & 0x3fff | 0x8000)) \
$RANDOM $RANDOM $RANDOM)"
echo -n "$uuid"
}
if [ "$#" != 2 ] ; then
echo "Usage: $(basename "$0") <docker-image-name> <output-directory>"
exit 1
fi
tmpdir="$(mktemp -d)"
mkdir -p "$outdir"
cont_name="export_image_temp_$(make_uuid)"
docker create --name "$cont_name" "$image" xxyyz > /dev/null
docker export "$cont_name" -o "$tmpdir"/export.tar
docker rm -f "$cont_name" > /dev/null 2>&1
tar -xpf "$tmpdir"/export.tar -C "$outdir"
rm -rf "$tmpdir"
echo "Image $image exported to $outdir."