attach.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:bay 作者: eventbrite 项目源码 文件源码
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,
    )))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号