1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

New Dockerfile operation 'expose' exposes default tcp ports

This commit is contained in:
Solomon Hykes 2013-05-01 14:16:56 -07:00
parent 5c30faf6f7
commit 08812096f5

View file

@ -49,14 +49,17 @@ def docker(args, stdin=None):
def image_exists(img): def image_exists(img):
return docker(["inspect", img]).read().strip() != "" return docker(["inspect", img]).read().strip() != ""
def run_and_commit(img_in, cmd, stdin=None, author=None): def image_config(img):
return json.loads(docker(["inspect", img]).read()).get("Config", {})
def run_and_commit(img_in, cmd, stdin=None, author=None, run=None):
run_id = docker(["run"] + (["-i", "-a", "stdin"] if stdin else ["-d"]) + [img_in, "/bin/sh", "-c", cmd], stdin=stdin).read().rstrip() run_id = docker(["run"] + (["-i", "-a", "stdin"] if stdin else ["-d"]) + [img_in, "/bin/sh", "-c", cmd], stdin=stdin).read().rstrip()
print "---> Waiting for " + run_id print "---> Waiting for " + run_id
result=int(docker(["wait", run_id]).read().rstrip()) result=int(docker(["wait", run_id]).read().rstrip())
if result != 0: if result != 0:
print "!!! '{}' return non-zero exit code '{}'. Aborting.".format(cmd, result) print "!!! '{}' return non-zero exit code '{}'. Aborting.".format(cmd, result)
sys.exit(1) sys.exit(1)
return docker(["commit"] + (["-author", author] if author else []) + [run_id]).read().rstrip() return docker(["commit"] + (["-author", author] if author else []) + (["-run", json.dumps(run)] if run is not None else []) + [run_id]).read().rstrip()
def insert(base, src, dst, author=None): def insert(base, src, dst, author=None):
print "COPY {} to {} in {}".format(src, dst, base) print "COPY {} to {} in {}".format(src, dst, base)
@ -106,6 +109,14 @@ def main():
steps.append(result) steps.append(result)
base=result base=result
print "===> " + base print "===> " + base
elif op == "expose":
config = image_config(base)
portspec = param.strip()
config.setdefault("PortSpecs", []).append(portspec)
result = run_and_commit(base, "# (nop) expose port {}".format(portspec), author=maintainer, run=config)
steps.append(result)
base=result
print "===> " + base
else: else:
print "Skipping uknown op " + op print "Skipping uknown op " + op
except: except: