Add detach to docker-toool

This lets you rerun the container as it was before killing it.

Change-Id: I12b8a1f7058bab621d68aa0e55b3be3e87854574
This commit is contained in:
Ian Main 2017-06-08 19:09:08 -04:00
parent d01de0e985
commit 3df4efff61
1 changed files with 10 additions and 6 deletions

View File

@ -69,10 +69,15 @@ def parse_opts(argv):
action='store_true',
help="""Start docker container interactively (-ti).""",
default=False)
parser.add_argument('-d', '--detach',
action='store_true',
help="""Start container detached.""",
default=False)
opts = parser.parse_args(argv[1:])
return opts
def docker_arg_map(key, value):
value = str(value).encode('ascii', 'ignore')
return {
@ -81,12 +86,12 @@ def docker_arg_map(key, value):
'net': "--net=%s" % value,
'pid': "--pid=%s" % value,
'privileged': "--privileged=%s" % value.lower(),
#'restart': "--restart=%s" % "false",
'user': "--user=%s" % value,
'volumes': "--volume=%s" % value,
'volumes_from': "--volumes-from=%s" % value,
}.get(key, None)
def run_docker_container(opts, container_name):
container_found = False
@ -139,13 +144,15 @@ def run_docker_container(opts, container_name):
if opts.user:
continue
arg = docker_arg_map(container_data,
json_data[step][container][container_data])
json_data[step][container][container_data])
if arg:
cmd.append(arg)
if opts.user:
cmd.append('--user')
cmd.append(opts.user)
if opts.detach:
cmd.append('--detach')
if opts.interactive:
cmd.append('-ti')
# May as well remove it when we're done too
@ -164,19 +171,17 @@ def run_docker_container(opts, container_name):
if not container_found:
print("Container '%s' not found!" % container_name)
def list_docker_containers(opts):
print opts
with open(opts.config) as f:
json_data = json.load(f)
for step in (json_data or []):
if step is None:
continue
print step
for container in (json_data[step] or []):
print('\tcontainer: %s' % container)
for container_data in (json_data[step][container] or []):
#print('\t\tcontainer_data: %s' % container_data)
if container_data == "start_order":
print('\t\tstart_order: %s' % json_data[step][container][container_data])
@ -186,4 +191,3 @@ if opts.container:
run_docker_container(opts, opts.container)
else:
list_docker_containers(opts)