summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey F <joffrey@docker.com>2017-08-28 17:35:55 -0700
committerJoffrey F <f.joffrey@gmail.com>2017-10-17 17:20:00 -0700
commit9587556e8f7d3ef745399f8423627a9a54b3dfdd (patch)
treec9bb46c80ec31aa62617867b60a08e7eeed1f47b
parent5b4573e7e5e379c0777cb8e38a71d612fe354db5 (diff)
Add --no-start flag to up command. Deprecate create command.
Signed-off-by: Joffrey F <joffrey@docker.com>
-rw-r--r--compose/cli/main.py18
-rw-r--r--compose/project.py6
-rw-r--r--tests/acceptance/cli_test.py25
3 files changed, 45 insertions, 4 deletions
diff --git a/compose/cli/main.py b/compose/cli/main.py
index 83bc7d58..21bf1f30 100644
--- a/compose/cli/main.py
+++ b/compose/cli/main.py
@@ -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)
diff --git a/compose/project.py b/compose/project.py
index 2310a2fc..c8b57edd 100644
--- a/compose/project.py
+++ b/compose/project.py
@@ -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):
diff --git a/tests/acceptance/cli_test.py b/tests/acceptance/cli_test.py
index e721b940..3a5e17ad 100644
--- a/tests/acceptance/cli_test.py
+++ b/tests/acceptance/cli_test.py
@@ -777,6 +777,31 @@ class CLITestCase(DockerClientTestCase):
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'
result = self.dispatch(['--no-ansi', 'up', '-d'], None)