mirror of
https://github.com/docker/compose.git
synced 2025-07-23 05:34:36 +02:00
CLI: Add --detach option for up, run and exec commands
This contribution allows the usage of --detach option when running: docker-compose run --detach docker-compose exec --detach docker-compose up --detach The behavior is the same as the -d option. Signed-off-by: Gustavo Pantuza Coelho Pinto <gustavopantuza@gmail.com>
This commit is contained in:
parent
1b3acd0be8
commit
1833860614
@ -424,7 +424,7 @@ class TopLevelCommand(object):
|
|||||||
Usage: exec [options] [-e KEY=VAL...] SERVICE COMMAND [ARGS...]
|
Usage: exec [options] [-e KEY=VAL...] SERVICE COMMAND [ARGS...]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-d Detached mode: Run command in the background.
|
-d, --detach Detached mode: Run command in the background.
|
||||||
--privileged Give extended privileges to the process.
|
--privileged Give extended privileges to the process.
|
||||||
-u, --user USER Run the command as this user.
|
-u, --user USER Run the command as this user.
|
||||||
-T Disable pseudo-tty allocation. By default `docker-compose exec`
|
-T Disable pseudo-tty allocation. By default `docker-compose exec`
|
||||||
@ -438,7 +438,7 @@ class TopLevelCommand(object):
|
|||||||
use_cli = not environment.get_boolean('COMPOSE_INTERACTIVE_NO_CLI')
|
use_cli = not environment.get_boolean('COMPOSE_INTERACTIVE_NO_CLI')
|
||||||
index = int(options.get('--index'))
|
index = int(options.get('--index'))
|
||||||
service = self.project.get_service(options['SERVICE'])
|
service = self.project.get_service(options['SERVICE'])
|
||||||
detach = options['-d']
|
detach = options.get('-d') or options.get('--detach')
|
||||||
|
|
||||||
if options['--env'] and docker.utils.version_lt(self.project.client.api_version, '1.25'):
|
if options['--env'] and docker.utils.version_lt(self.project.client.api_version, '1.25'):
|
||||||
raise UserError("Setting environment for exec is not supported in API < 1.25'")
|
raise UserError("Setting environment for exec is not supported in API < 1.25'")
|
||||||
@ -762,7 +762,7 @@ class TopLevelCommand(object):
|
|||||||
SERVICE [COMMAND] [ARGS...]
|
SERVICE [COMMAND] [ARGS...]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-d Detached mode: Run container in the background, print
|
-d --detach Detached mode: Run container in the background, print
|
||||||
new container name.
|
new container name.
|
||||||
--name NAME Assign a name to the container
|
--name NAME Assign a name to the container
|
||||||
--entrypoint CMD Override the entrypoint of the image.
|
--entrypoint CMD Override the entrypoint of the image.
|
||||||
@ -780,7 +780,7 @@ class TopLevelCommand(object):
|
|||||||
-w, --workdir="" Working directory inside the container
|
-w, --workdir="" Working directory inside the container
|
||||||
"""
|
"""
|
||||||
service = self.project.get_service(options['SERVICE'])
|
service = self.project.get_service(options['SERVICE'])
|
||||||
detach = options['-d']
|
detach = options.get('-d') or options.get('--detach')
|
||||||
|
|
||||||
if options['--publish'] and options['--service-ports']:
|
if options['--publish'] and options['--service-ports']:
|
||||||
raise UserError(
|
raise UserError(
|
||||||
@ -928,7 +928,7 @@ class TopLevelCommand(object):
|
|||||||
Usage: up [options] [--scale SERVICE=NUM...] [SERVICE...]
|
Usage: up [options] [--scale SERVICE=NUM...] [SERVICE...]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-d Detached mode: Run containers in the background,
|
-d, --detach Detached mode: Run containers in the background,
|
||||||
print new container names. Incompatible with
|
print new container names. Incompatible with
|
||||||
--abort-on-container-exit.
|
--abort-on-container-exit.
|
||||||
--no-color Produce monochrome output.
|
--no-color Produce monochrome output.
|
||||||
@ -963,7 +963,7 @@ class TopLevelCommand(object):
|
|||||||
service_names = options['SERVICE']
|
service_names = options['SERVICE']
|
||||||
timeout = timeout_from_opts(options)
|
timeout = timeout_from_opts(options)
|
||||||
remove_orphans = options['--remove-orphans']
|
remove_orphans = options['--remove-orphans']
|
||||||
detached = options.get('-d')
|
detached = options.get('-d') or options.get('--detach')
|
||||||
no_start = options.get('--no-start')
|
no_start = options.get('--no-start')
|
||||||
|
|
||||||
if detached and (cascade_stop or exit_value_from):
|
if detached and (cascade_stop or exit_value_from):
|
||||||
@ -975,7 +975,7 @@ class TopLevelCommand(object):
|
|||||||
if ignore_orphans and remove_orphans:
|
if ignore_orphans and remove_orphans:
|
||||||
raise UserError("COMPOSE_IGNORE_ORPHANS and --remove-orphans cannot be combined.")
|
raise UserError("COMPOSE_IGNORE_ORPHANS and --remove-orphans cannot be combined.")
|
||||||
|
|
||||||
opts = ['-d', '--abort-on-container-exit', '--exit-code-from']
|
opts = ['--detach', '--abort-on-container-exit', '--exit-code-from']
|
||||||
for excluded in [x for x in opts if options.get(x) and no_start]:
|
for excluded in [x for x in opts if options.get(x) and no_start]:
|
||||||
raise UserError('--no-start and {} cannot be combined.'.format(excluded))
|
raise UserError('--no-start and {} cannot be combined.'.format(excluded))
|
||||||
|
|
||||||
@ -1245,7 +1245,7 @@ def run_one_off_container(container_options, project, service, options, project_
|
|||||||
one_off=True,
|
one_off=True,
|
||||||
**container_options)
|
**container_options)
|
||||||
|
|
||||||
if options['-d']:
|
if options.get('-d') or options.get('--detach'):
|
||||||
service.start_container(container)
|
service.start_container(container)
|
||||||
print(container.name)
|
print(container.name)
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user