Added map service ports option for run command.

When using the fig run command, ports defined in fig.yml can be mapped
to the host computer using the -service-ports option.

Signed-off-by: Stephen Quebe <squebe@gmail.com>
This commit is contained in:
Stephen Quebe 2014-09-15 18:18:03 -04:00 committed by Stephen
commit cc834aa564
3 changed files with 49 additions and 3 deletions

View file

@ -278,6 +278,8 @@ class TopLevelCommand(Command):
-e KEY=VAL Set an environment variable (can be used multiple times)
--no-deps Don't start linked services.
--rm Remove container after run. Ignored in detached mode.
--service-ports Run command with the service's ports enabled and mapped
to the host.
-T Disable pseudo-tty allocation. By default `fig run`
allocates a TTY.
"""
@ -325,11 +327,15 @@ class TopLevelCommand(Command):
insecure_registry=insecure_registry,
**container_options
)
service_ports = None
if options['--service-ports']:
service_ports = service.options['ports']
if options['-d']:
service.start_container(container, ports=None, one_off=True)
service.start_container(container, ports=service_ports, one_off=True)
print(container.name)
else:
service.start_container(container, ports=None, one_off=True)
service.start_container(container, ports=service_ports, one_off=True)
dockerpty.start(project.client, container.id, interactive=not options['-T'])
exit_code = container.wait()
if options['--rm']: