Skip to content

Instantly share code, notes, and snippets.

@benob
Created September 14, 2020 19:44
Show Gist options
  • Save benob/0b147ef6a44826061d12648ed1b5031c to your computer and use it in GitHub Desktop.
Save benob/0b147ef6a44826061d12648ed1b5031c to your computer and use it in GitHub Desktop.
Extract a docker image retrieved with docker_pull.py (https://github.com/NotGlop/docker-drag)
# Extract a docker image retrieved with docker_pull.py (https://github.com/NotGlop/docker-drag)
import tarfile
import sys, json
# The tar contains a manifest.json which lists layers; each layer is a tar archive
with tarfile.TarFile(sys.argv[1]) as tf:
with tf.extractfile("manifest.json") as manifest_fp:
manifest = json.loads(manifest_fp.read())
for layername in manifest[0]['Layers']:
with tf.extractfile(layername) as layer_fp:
with tarfile.TarFile(fileobj=layer_fp) as layer_tar:
for member in layer_tar.getmembers():
if not member.isdev():
print(member.name)
layer_tar.extract(member)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment