Add --no-start flag to up command. Deprecate create command.

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2017-08-28 17:35:55 -07:00 committed by Joffrey F
parent 5b4573e7e5
commit 9587556e8f
3 changed files with 45 additions and 4 deletions

View File

@ -319,6 +319,7 @@ class TopLevelCommand(object):
def create(self, options):
"""
Creates containers for a service.
This command is deprecated. Use the `up` command with `--no-start` instead.
Usage: create [options] [SERVICE...]
@ -332,6 +333,11 @@ class TopLevelCommand(object):
"""
service_names = options['SERVICE']
log.warn(
'The create command is deprecated. '
'Use the up command with the --no-start flag instead.'
)
self.project.create(
service_names=service_names,
strategy=convergence_strategy_from_opts(options),
@ -902,6 +908,7 @@ class TopLevelCommand(object):
--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.
--no-start Don't start the services after creating them.
--build Build images before starting containers.
--abort-on-container-exit Stops all containers if any container was stopped.
Incompatible with -d.
@ -922,10 +929,16 @@ class TopLevelCommand(object):
timeout = timeout_from_opts(options)
remove_orphans = options['--remove-orphans']
detached = options.get('-d')
no_start = options.get('--no-start')
if detached and cascade_stop:
if detached and (cascade_stop or exit_value_from):
raise UserError("--abort-on-container-exit and -d cannot be combined.")
if no_start:
for excluded in ['-d', '--abort-on-container-exit', '--exit-code-from']:
if options.get(excluded):
raise UserError('--no-start and {} cannot be combined.'.format(excluded))
with up_shutdown_context(self.project, service_names, timeout, detached):
to_attach = self.project.up(
service_names=service_names,
@ -936,9 +949,10 @@ class TopLevelCommand(object):
detached=detached,
remove_orphans=remove_orphans,
scale_override=parse_scale_args(options['--scale']),
start=not no_start
)
if detached:
if detached or no_start:
return
attached_containers = filter_containers_to_service_names(to_attach, service_names)

View File

@ -412,7 +412,8 @@ class Project(object):
detached=False,
remove_orphans=False,
scale_override=None,
rescale=True):
rescale=True,
start=True):
warn_for_swarm_mode(self.client)
@ -436,7 +437,8 @@ class Project(object):
timeout=timeout,
detached=detached,
scale_override=scale_override.get(service.name),
rescale=rescale
rescale=rescale,
start=start
)
def get_deps(service):

View File

@ -776,6 +776,31 @@ class CLITestCase(DockerClientTestCase):
for service in services:
assert self.lookup(container, service.name)
@v2_only()
def test_up_no_start(self):
self.base_dir = 'tests/fixtures/v2-full'
self.dispatch(['up', '--no-start'], None)
services = self.project.get_services()
default_network = self.project.networks.networks['default'].full_name
front_network = self.project.networks.networks['front'].full_name
networks = self.client.networks(names=[default_network, front_network])
assert len(networks) == 2
for service in services:
containers = service.containers(stopped=True)
assert len(containers) == 1
container = containers[0]
assert not container.is_running
assert container.get('State.Status') == 'created'
volumes = self.project.volumes.volumes
assert 'data' in volumes
volume = volumes['data']
assert volume.exists()
@v2_only()
def test_up_no_ansi(self):
self.base_dir = 'tests/fixtures/v2-simple'