def attach(app, container, host, command):
"""
Attaches to a container
"""
if command:
shell = ['/bin/bash', '-lc', ' '.join(command)]
else:
shell = ['/bin/bash']
# See if the container is running
formation = FormationIntrospector(host, app.containers).introspect()
for instance in formation:
if instance.container == container:
# Work out anything to put before the shell (e.g. ENV)
pre_args = []
if os.environ.get("TERM", None):
pre_args = ["env", "TERM=%s" % os.environ['TERM']]
# Launch into an attached shell
status_code = subprocess.call(["docker", "exec", "-it", instance.name] + pre_args + shell)
sys.exit(status_code)
# It's not running ;(
click.echo(RED("Container {name} is not running. It must be started to attach - try `bay run {name}`.".format(
name=container.name,
)))
评论列表
文章目录