mirror of https://github.com/docker/compose.git
Prevent attempts to create image names starting with - or _
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
6e30c130d5
commit
b00db08aa9
|
@ -363,7 +363,9 @@ class Service(object):
|
|||
|
||||
@property
|
||||
def image_name(self):
|
||||
return self.options.get('image', '{s.project}_{s.name}'.format(s=self))
|
||||
return self.options.get('image', '{project}_{s.name}'.format(
|
||||
s=self, project=self.project.lstrip('_-')
|
||||
))
|
||||
|
||||
@property
|
||||
def platform(self):
|
||||
|
|
|
@ -1137,6 +1137,21 @@ class ServiceTest(DockerClientTestCase):
|
|||
service.build()
|
||||
assert service.image()
|
||||
|
||||
def test_build_with_illegal_leading_chars(self):
|
||||
base_dir = tempfile.mkdtemp()
|
||||
self.addCleanup(shutil.rmtree, base_dir)
|
||||
with open(os.path.join(base_dir, 'Dockerfile'), 'w') as f:
|
||||
f.write('FROM busybox\nRUN echo "Embodiment of Scarlet Devil"\n')
|
||||
service = Service(
|
||||
'build_leading_slug', client=self.client,
|
||||
project='___-composetest', build={
|
||||
'context': text_type(base_dir)
|
||||
}
|
||||
)
|
||||
assert service.image_name == 'composetest_build_leading_slug'
|
||||
service.build()
|
||||
assert service.image()
|
||||
|
||||
def test_start_container_stays_unprivileged(self):
|
||||
service = self.create_service('web')
|
||||
container = create_and_start_container(service).inspect()
|
||||
|
|
Loading…
Reference in New Issue