Skip to content

Instantly share code, notes, and snippets.

@victor141516
Last active March 25, 2019 15:47
Show Gist options
  • Save victor141516/92a5a2c0bb943b031333331f199033e4 to your computer and use it in GitHub Desktop.
Save victor141516/92a5a2c0bb943b031333331f199033e4 to your computer and use it in GitHub Desktop.
Extract all layers of a Docker image as files
#!/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