Created
June 7, 2017 07:32
-
-
Save bogdanRada/9127168d5032c9bc59b7547319136810 to your computer and use it in GitHub Desktop.
to flatten dhrp/sshd : sudo python flatten.py 2bbfe079a94259b229ae66962d9d06b97fcdce7a5449775ef738bb619ff8ce73 it'll produce a 42422bbfe079a94259b229ae66962d9d06b97fcdce7a5449775ef738bb619ff8ce73 image
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
import os | |
from StringIO import StringIO | |
import json | |
import sys | |
import subprocess | |
import shutil | |
def getParent(rootid, id): | |
print "--> ", id | |
with open("/var/lib/docker/graph/"+id+"/json") as data_file: | |
data = json.load(data_file) | |
if "parent" in data: | |
parent = data["parent"] | |
getParent(rootid, parent) | |
print "[cp -r /var/lib/docker/graph/"+id+"/* /var/lib/docker/graph/4242"+rootid+"/]" | |
os.system("cp -r /var/lib/docker/graph/"+id+"/* /var/lib/docker/graph/4242"+rootid+"/") | |
rootid = sys.argv[-1] | |
shutil.rmtree(path="/var/lib/docker/graph/4242"+rootid,ignore_errors=True) | |
print "[mkdir /var/lib/docker/graph/4242"+rootid+"]" | |
os.mkdir("/var/lib/docker/graph/4242"+rootid) | |
getParent(rootid, rootid) | |
data = [] | |
with open("/var/lib/docker/graph/4242"+rootid+"/json", "r") as data_file: | |
data = json.load(data_file) | |
data["id"] = "4242" + data["id"] | |
del data["parent"] | |
del data["Size"] | |
with open("/var/lib/docker/graph/4242"+rootid+"/json", "w") as data_file: | |
json.dump(data, data_file) | |
shutil.rmtree(path="/var/lib/docker/graph/4242"+rootid+"/layersize",ignore_errors=True) | |
print "==> 4242"+rootid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment