mirror of https://github.com/docker/compose.git
Modified scale awareness from exception to warning
Signed-off-by: André Martins <martins@noironetworks.com>
This commit is contained in:
parent
1344099e29
commit
ae63d35660
|
@ -13,7 +13,7 @@ import dockerpty
|
||||||
from .. import __version__
|
from .. import __version__
|
||||||
from .. import legacy
|
from .. import legacy
|
||||||
from ..project import NoSuchService, ConfigurationError
|
from ..project import NoSuchService, ConfigurationError
|
||||||
from ..service import BuildError, CannotBeScaledError, NeedsBuildError
|
from ..service import BuildError, NeedsBuildError
|
||||||
from ..config import parse_environment
|
from ..config import parse_environment
|
||||||
from .command import Command
|
from .command import Command
|
||||||
from .docopt_command import NoSuchCommand
|
from .docopt_command import NoSuchCommand
|
||||||
|
@ -372,15 +372,7 @@ class TopLevelCommand(Command):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise UserError('Number of containers for service "%s" is not a '
|
raise UserError('Number of containers for service "%s" is not a '
|
||||||
'number' % service_name)
|
'number' % service_name)
|
||||||
try:
|
project.get_service(service_name).scale(num)
|
||||||
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)
|
|
||||||
|
|
||||||
def start(self, project, options):
|
def start(self, project, options):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -55,10 +55,6 @@ class BuildError(Exception):
|
||||||
self.reason = reason
|
self.reason = reason
|
||||||
|
|
||||||
|
|
||||||
class CannotBeScaledError(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class ConfigError(ValueError):
|
class ConfigError(ValueError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -154,7 +150,9 @@ class Service(object):
|
||||||
- removes all stopped containers
|
- removes all stopped containers
|
||||||
"""
|
"""
|
||||||
if not self.can_be_scaled():
|
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
|
# Create enough containers
|
||||||
containers = self.containers(stopped=True)
|
containers = self.containers(stopped=True)
|
||||||
|
|
|
@ -17,7 +17,6 @@ from compose.const import (
|
||||||
LABEL_VERSION,
|
LABEL_VERSION,
|
||||||
)
|
)
|
||||||
from compose.service import (
|
from compose.service import (
|
||||||
CannotBeScaledError,
|
|
||||||
ConfigError,
|
ConfigError,
|
||||||
Service,
|
Service,
|
||||||
build_extra_hosts,
|
build_extra_hosts,
|
||||||
|
@ -526,10 +525,6 @@ class ServiceTest(DockerClientTestCase):
|
||||||
service.scale(0)
|
service.scale(0)
|
||||||
self.assertEqual(len(service.containers()), 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):
|
def test_scale_sets_ports(self):
|
||||||
service = self.create_service('web', ports=['8000'])
|
service = self.create_service('web', ports=['8000'])
|
||||||
service.scale(2)
|
service.scale(2)
|
||||||
|
|
Loading…
Reference in New Issue