Created
September 14, 2020 19:44
-
-
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)
This file contains hidden or 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
# 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