Support legacy tmpfs mounts

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2018-01-10 12:16:59 -08:00
parent c4fda0834d
commit 397aa20dfc
3 changed files with 27 additions and 2 deletions

View File

@ -183,6 +183,10 @@ class MountSpec(object):
def is_named_volume(self):
return self.type == 'volume' and self.source
@property
def is_tmpfs(self):
return self.type == 'tmpfs'
@property
def external(self):
return self.source

View File

@ -834,8 +834,14 @@ class Service(object):
if version_gte(self.client.api_version, '1.30'):
override_options['mounts'] = [build_mount(v) for v in container_mounts] or None
else:
override_options['binds'].extend(m.legacy_repr() for m in container_mounts)
container_options['volumes'].update((m.target, {}) for m in container_mounts)
# Workaround for 3.2 format
self.options['tmpfs'] = self.options.get('tmpfs') or []
for m in container_mounts:
if m.is_tmpfs:
self.options['tmpfs'].append(m.target)
else:
override_options['binds'].append(m.legacy_repr())
container_options['volumes'][m.target] = {}
secret_volumes = self.get_secret_volumes()
if secret_volumes:

View File

@ -346,6 +346,21 @@ class ServiceTest(DockerClientTestCase):
assert mount
assert mount['Name'] == volume_name
@v3_only()
def test_create_container_with_legacy_tmpfs_mount(self):
# Ensure tmpfs mounts are converted to tmpfs entries if API version < 1.30
# Needed to support long syntax in the 3.2 format
client = docker_client({}, version='1.25')
container_path = '/container-tmpfs'
service = Service('db', client=client, volumes=[
MountSpec(type='tmpfs', target=container_path)
], image='busybox:latest', command=['top'], project='composetest')
container = service.create_container()
service.start_container(container)
mount = container.get_mount(container_path)
assert mount is None
assert container_path in container.get('HostConfig.Tmpfs')
def test_create_container_with_healthcheck_config(self):
one_second = parse_nanoseconds_int('1s')
healthcheck = {