diff --git a/compose/service.py b/compose/service.py index 89851e070..012499afe 100644 --- a/compose/service.py +++ b/compose/service.py @@ -47,7 +47,7 @@ DOCKER_START_KEYS = [ 'security_opt', ] -VALID_NAME_CHARS = '[a-zA-Z0-9]' +VALID_NAME_CHARS = '[a-zA-Z0-9\._\-]' class BuildError(Exception): diff --git a/tests/unit/service_test.py b/tests/unit/service_test.py index f99cbbc9d..0327874c1 100644 --- a/tests/unit/service_test.py +++ b/tests/unit/service_test.py @@ -28,24 +28,29 @@ class ServiceTest(unittest.TestCase): self.mock_client = mock.create_autospec(docker.Client) def test_name_validations(self): - self.assertRaises(ConfigError, lambda: Service(name='')) + self.assertRaises(ConfigError, lambda: Service(name='', image='foo')) - self.assertRaises(ConfigError, lambda: Service(name=' ')) - self.assertRaises(ConfigError, lambda: Service(name='/')) - self.assertRaises(ConfigError, lambda: Service(name='!')) - self.assertRaises(ConfigError, lambda: Service(name='\xe2')) - self.assertRaises(ConfigError, lambda: Service(name='_')) - self.assertRaises(ConfigError, lambda: Service(name='____')) - self.assertRaises(ConfigError, lambda: Service(name='foo_bar')) - self.assertRaises(ConfigError, lambda: Service(name='__foo_bar__')) + self.assertRaises(ConfigError, lambda: Service(name=' ', image='foo')) + self.assertRaises(ConfigError, lambda: Service(name='/', image='foo')) + self.assertRaises(ConfigError, lambda: Service(name='!', image='foo')) + self.assertRaises(ConfigError, lambda: Service(name='\xe2', image='foo')) Service('a', image='foo') Service('foo', image='foo') + Service('foo-bar', image='foo') + Service('foo.bar', image='foo') + Service('foo_bar', image='foo') + Service('_', image='foo') + Service('___', image='foo') + Service('-', image='foo') + Service('--', image='foo') + Service('.__.', image='foo') def test_project_validation(self): self.assertRaises(ConfigError, lambda: Service('bar')) - self.assertRaises(ConfigError, lambda: Service(name='foo', project='_', image='foo')) - Service(name='foo', project='bar', image='foo') + self.assertRaises(ConfigError, lambda: Service(name='foo', project='>', image='foo')) + + Service(name='foo', project='bar.bar__', image='foo') def test_containers(self): service = Service('db', self.mock_client, 'myproject', image='foo')