Last active
March 25, 2019 15:47
-
-
Save victor141516/92a5a2c0bb943b031333331f199033e4 to your computer and use it in GitHub Desktop.
Extract all layers of a Docker image as files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ $# -eq 0 ] | |
then | |
echo "Usage: doxtrak [docker image name]" | |
exit | |
fi | |
echo "Extracting..." | |
mkdir -p $1 && \ | |
pushd $1 > /dev/null && \ | |
docker save $1 | tar x && \ | |
cat manifest.json \ | |
| jq -r '.[0].Layers | to_entries[] | [.key, .value] | @csv' \ | |
| tr ',' ' ' \ | |
| sed -E 's/^([0-9][0-9]*) \"(.*)\/layer.tar"/mkdir -p \1-\2 \&\& tar xf \"\2\/layer.tar" -C \1-\2 \&\& rm -rf \2;/' \ | |
| sh | |
rm repositories *.json && popd > /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment