'Builds, (re)creates, starts, and attaches to containers for a service.
Unless they are already running, this command also starts any linked services.
The `docker-compose up` command aggregates the output of each container. When
the command exits, all containers are stopped. Running `docker-compose up -d`
starts the containers in the background and leaves them running.
If there are existing containers for a service, and the service\'s configuration
or image was changed after the container\'s creation, `docker-compose up` picks
up the changes by stopping and recreating the containers (preserving mounted
volumes). To prevent Compose from picking up changes, use the `--no-recreate`
flag.
If you want to force Compose to stop and recreate all containers, use the
`--force-recreate` flag.
Usage: up [options] [--scale SERVICE=NUM...] [SERVICE...]
Options:
-d                         Detached mode: Run containers in the background,
print new container names.
Incompatible with --abort-on-container-exit.
--no-color                 Produce monochrome output.
--no-deps                  Don\'t start linked services.
--force-recreate           Recreate containers even if their configuration
and image haven\'t changed.
Incompatible with --no-recreate.
--no-recreate              If containers already exist, don\'t recreate them.
Incompatible with --force-recreate.
--no-build                 Don\'t build an image, even if it\'s missing.
--build                    Build images before starting containers.
--abort-on-container-exit  Stops all containers if any container was stopped.
Incompatible with -d.
-t, --timeout TIMEOUT      Use this timeout in seconds for container shutdown
when attached or when containers are already
running. (default: 10)
--remove-orphans           Remove containers for services not
defined in the Compose file
--exit-code-from SERVICE   Return the exit code of the selected service container.
Implies --abort-on-container-exit.
--scale SERVICE=NUM        Scale SERVICE to NUM instances. Overrides the `scale`
setting in the Compose file if present.'

def up(self, options):

    start_deps = (not options[u'--no-deps'])
    exit_value_from = exitval_from_opts(options, self.project)
    cascade_stop = options[u'--abort-on-container-exit']
    service_names = options[u'SERVICE']
    timeout = timeout_from_opts(options)
    remove_orphans = options[u'--remove-orphans']
    detached = options.get(u'-d')
    if (detached and cascade_stop):
        raise UserError(u'--abort-on-container-exit    and    -d    cannot    be    combined.')
    with up_shutdown_context(self.project, service_names, timeout, detached):
        to_attach = self.project.up(service_names=service_names, start_deps=start_deps, strategy=convergence_strategy_from_opts(options), do_build=build_action_from_opts(options), timeout=timeout, detached=detached, remove_orphans=remove_orphans, scale_override=parse_scale_args(options[u'--scale']))
        if detached:
            return
        attached_containers = filter_containers_to_service_names(to_attach, service_names)
        log_printer = log_printer_from_project(self.project, attached_containers, options[u'--no-color'], {u'follow': True}, cascade_stop, event_stream=self.project.events(service_names=service_names))
        print(u'Attaching    to', list_containers(log_printer.containers))
        cascade_starter = log_printer.run()
        if cascade_stop:
            print(u'Aborting    on    container    exit...')
            exit_code = 0
            if exit_value_from:
                candidates = list(filter((lambda c: (c.service == exit_value_from)), attached_containers))
                if (not candidates):
                    log.error(u'No    containers    matching    the    spec    "{0}"    were    run.'.format(exit_value_from))
                    exit_code = 2
                elif (len(candidates) > 1):
                    exit_values = filter((lambda e: (e != 0)), [c.inspect()[u'State'][u'ExitCode'] for c in candidates])
                    exit_code = exit_values[0]
                else:
                    exit_code = candidates[0].inspect()[u'State'][u'ExitCode']
            else:
                for e in self.project.containers(service_names=options[u'SERVICE'], stopped=True):
                    if ((not e.is_running) and (cascade_starter == e.name)):
                        if (not (e.exit_code == 0)):
                            exit_code = e.exit_code
                            break
            self.project.stop(service_names=service_names, timeout=timeout)
            sys.exit(exit_code)
