mirror of
https://github.com/docker/compose.git
synced 2025-07-21 12:44:54 +02:00
Support volumes in config with an unspecified host path
This commit is contained in:
parent
207e83ac2f
commit
3669236aa1
@ -114,8 +114,9 @@ class Service(object):
|
|||||||
|
|
||||||
if options.get('volumes', None) is not None:
|
if options.get('volumes', None) is not None:
|
||||||
for volume in options['volumes']:
|
for volume in options['volumes']:
|
||||||
external_dir, internal_dir = volume.split(':')
|
if ':' in volume:
|
||||||
volume_bindings[os.path.abspath(external_dir)] = internal_dir
|
external_dir, internal_dir = volume.split(':')
|
||||||
|
volume_bindings[os.path.abspath(external_dir)] = internal_dir
|
||||||
|
|
||||||
container.start(
|
container.start(
|
||||||
links=self._get_links(),
|
links=self._get_links(),
|
||||||
@ -162,7 +163,7 @@ class Service(object):
|
|||||||
container_options['ports'] = ports
|
container_options['ports'] = ports
|
||||||
|
|
||||||
if 'volumes' in container_options:
|
if 'volumes' in container_options:
|
||||||
container_options['volumes'] = dict((v.split(':')[1], {}) for v in container_options['volumes'])
|
container_options['volumes'] = dict((split_volume(v)[1], {}) for v in container_options['volumes'])
|
||||||
|
|
||||||
if self.can_be_built():
|
if self.can_be_built():
|
||||||
if len(self.client.images(name=self._build_tag_name())) == 0:
|
if len(self.client.images(name=self._build_tag_name())) == 0:
|
||||||
@ -233,3 +234,14 @@ def get_container_name(container):
|
|||||||
for name in container['Names']:
|
for name in container['Names']:
|
||||||
if len(name.split('/')) == 2:
|
if len(name.split('/')) == 2:
|
||||||
return name[1:]
|
return name[1:]
|
||||||
|
|
||||||
|
|
||||||
|
def split_volume(v):
|
||||||
|
"""
|
||||||
|
If v is of the format EXTERNAL:INTERNAL, returns (EXTERNAL, INTERNAL).
|
||||||
|
If v is of the format INTERNAL, returns (None, INTERNAL).
|
||||||
|
"""
|
||||||
|
if ':' in v:
|
||||||
|
return v.split(':', 1)
|
||||||
|
else:
|
||||||
|
return (None, v)
|
||||||
|
@ -102,6 +102,12 @@ class ServiceTest(DockerClientTestCase):
|
|||||||
container = db.create_container(one_off=True)
|
container = db.create_container(one_off=True)
|
||||||
self.assertEqual(container.name, 'figtest_db_run_1')
|
self.assertEqual(container.name, 'figtest_db_run_1')
|
||||||
|
|
||||||
|
def test_create_container_with_unspecified_volume(self):
|
||||||
|
service = self.create_service('db', volumes=['/var/db'])
|
||||||
|
container = service.create_container()
|
||||||
|
service.start_container(container)
|
||||||
|
self.assertIn('/var/db', container.inspect()['Volumes'])
|
||||||
|
|
||||||
def test_recreate_containers(self):
|
def test_recreate_containers(self):
|
||||||
service = self.create_service('db', environment={'FOO': '1'})
|
service = self.create_service('db', environment={'FOO': '1'})
|
||||||
container = service.create_container()
|
container = service.create_container()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user