Skip to content

Commit cd7f670

Browse files
committed
Merge pull request docker#1466 from noironetworks/changing-scale-to-warning
Modified scale awareness from exception to warning (cherry picked from commit 7d2a894) Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
1 parent b7e8770 commit cd7f670

File tree

3 files changed

+5
-20
lines changed

3 files changed

+5
-20
lines changed

compose/cli/main.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from .. import legacy
1414
from ..project import NoSuchService, ConfigurationError
15-
from ..service import BuildError, CannotBeScaledError, NeedsBuildError
15+
from ..service import BuildError, NeedsBuildError
1616
from ..config import parse_environment
1717
from .command import Command
1818
from .docopt_command import NoSuchCommand
@@ -371,15 +371,7 @@ def scale(self, project, options):
371371
except ValueError:
372372
raise UserError('Number of containers for service "%s" is not a '
373373
'number' % service_name)
374-
try:
375-
project.get_service(service_name).scale(num)
376-
except CannotBeScaledError:
377-
raise UserError(
378-
'Service "%s" cannot be scaled because it specifies a port '
379-
'on the host. If multiple containers for this service were '
380-
'created, the port would clash.\n\nRemove the ":" from the '
381-
'port definition in docker-compose.yml so Docker can choose a random '
382-
'port for each container.' % service_name)
374+
project.get_service(service_name).scale(num)
383375

384376
def start(self, project, options):
385377
"""

compose/service.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ def __init__(self, service, reason):
5555
self.reason = reason
5656

5757

58-
class CannotBeScaledError(Exception):
59-
pass
60-
61-
6258
class ConfigError(ValueError):
6359
pass
6460

@@ -154,7 +150,9 @@ def scale(self, desired_num):
154150
- removes all stopped containers
155151
"""
156152
if not self.can_be_scaled():
157-
raise CannotBeScaledError()
153+
log.warn('Service %s specifies a port on the host. If multiple containers '
154+
'for this service are created on a single host, the port will clash.'
155+
% self.name)
158156

159157
# Create enough containers
160158
containers = self.containers(stopped=True)

tests/integration/service_test.py

-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
LABEL_VERSION,
1818
)
1919
from compose.service import (
20-
CannotBeScaledError,
2120
ConfigError,
2221
Service,
2322
build_extra_hosts,
@@ -526,10 +525,6 @@ def test_scale(self):
526525
service.scale(0)
527526
self.assertEqual(len(service.containers()), 0)
528527

529-
def test_scale_on_service_that_cannot_be_scaled(self):
530-
service = self.create_service('web', ports=['8000:8000'])
531-
self.assertRaises(CannotBeScaledError, lambda: service.scale(1))
532-
533528
def test_scale_sets_ports(self):
534529
service = self.create_service('web', ports=['8000'])
535530
service.scale(2)

0 commit comments

Comments
 (0)