Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions compose/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .. import __version__
from .. import legacy
from ..project import NoSuchService, ConfigurationError
from ..service import BuildError, CannotBeScaledError, NeedsBuildError
from ..service import BuildError, NeedsBuildError
from ..config import parse_environment
from .command import Command
from .docopt_command import NoSuchCommand
Expand Down Expand Up @@ -372,15 +372,7 @@ def scale(self, project, options):
except ValueError:
raise UserError('Number of containers for service "%s" is not a '
'number' % service_name)
try:
project.get_service(service_name).scale(num)
except CannotBeScaledError:
raise UserError(
'Service "%s" cannot be scaled because it specifies a port '
'on the host. If multiple containers for this service were '
'created, the port would clash.\n\nRemove the ":" from the '
'port definition in docker-compose.yml so Docker can choose a random '
'port for each container.' % service_name)
project.get_service(service_name).scale(num)

def start(self, project, options):
"""
Expand Down
8 changes: 3 additions & 5 deletions compose/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ def __init__(self, service, reason):
self.reason = reason


class CannotBeScaledError(Exception):
pass


class ConfigError(ValueError):
pass

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

# Create enough containers
containers = self.containers(stopped=True)
Expand Down
5 changes: 0 additions & 5 deletions tests/integration/service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
LABEL_VERSION,
)
from compose.service import (
CannotBeScaledError,
ConfigError,
Service,
build_extra_hosts,
Expand Down Expand Up @@ -526,10 +525,6 @@ def test_scale(self):
service.scale(0)
self.assertEqual(len(service.containers()), 0)

def test_scale_on_service_that_cannot_be_scaled(self):
service = self.create_service('web', ports=['8000:8000'])
self.assertRaises(CannotBeScaledError, lambda: service.scale(1))

def test_scale_sets_ports(self):
service = self.create_service('web', ports=['8000'])
service.scale(2)
Expand Down