diff --git a/compose/config/config.py b/compose/config/config.py index 055ae18aca2..3c10af035e2 100644 --- a/compose/config/config.py +++ b/compose/config/config.py @@ -76,6 +76,7 @@ 'shm_size', 'stdin_open', 'stop_signal', + 'tmpfs', 'tty', 'user', 'volume_driver', @@ -589,6 +590,9 @@ def process_service(service_config): if 'extra_hosts' in service_dict: service_dict['extra_hosts'] = parse_extra_hosts(service_dict['extra_hosts']) + if 'tmpfs' in service_dict: + service_dict['tmpfs'] = to_list(service_dict['tmpfs']) + for field in ['dns', 'dns_search']: if field in service_dict: service_dict[field] = to_list(service_dict[field]) @@ -725,6 +729,7 @@ def merge_service_dicts(base, override, version): 'external_links', 'ports', 'volumes_from', + 'tmpfs', ]: md.merge_field(field, operator.add, default=[]) diff --git a/compose/config/service_schema_v1.json b/compose/config/service_schema_v1.json index 4d974d71084..0cd0a415e9b 100644 --- a/compose/config/service_schema_v1.json +++ b/compose/config/service_schema_v1.json @@ -101,6 +101,7 @@ "shm_size": {"type": ["number", "string"]}, "stdin_open": {"type": "boolean"}, "stop_signal": {"type": "string"}, + "tmpfs": {"$ref": "#/definitions/string_or_list"}, "tty": {"type": "boolean"}, "ulimits": { "type": "object", diff --git a/compose/config/service_schema_v2.0.json b/compose/config/service_schema_v2.0.json index edccedc664b..3b64b448fb3 100644 --- a/compose/config/service_schema_v2.0.json +++ b/compose/config/service_schema_v2.0.json @@ -160,6 +160,7 @@ "shm_size": {"type": ["number", "string"]}, "stdin_open": {"type": "boolean"}, "stop_signal": {"type": "string"}, + "tmpfs": {"$ref": "#/definitions/string_or_list"}, "tty": {"type": "boolean"}, "ulimits": { "type": "object", diff --git a/compose/service.py b/compose/service.py index 8b22b7d7580..0b26dfa0943 100644 --- a/compose/service.py +++ b/compose/service.py @@ -655,6 +655,7 @@ def _get_container_host_config(self, override_options, one_off=False): cgroup_parent=options.get('cgroup_parent'), cpu_quota=options.get('cpu_quota'), shm_size=options.get('shm_size'), + tmpfs=options.get('tmpfs'), ) def build(self, no_cache=False, pull=False, force_rm=False): diff --git a/docs/compose-file.md b/docs/compose-file.md index f446e2ab3ca..b768c817aa3 100644 --- a/docs/compose-file.md +++ b/docs/compose-file.md @@ -213,6 +213,15 @@ Custom DNS search domains. Can be a single value or a list. - dc1.example.com - dc2.example.com +### tmpfs + +RAM disks to mount inside the container. Can be a single value or a list. + + tmpfs: /run + tmpfs: + - /run + - /tmp + ### entrypoint Override the default entrypoint. diff --git a/docs/extends.md b/docs/extends.md index bceb02578a7..1be0622c1a6 100644 --- a/docs/extends.md +++ b/docs/extends.md @@ -316,8 +316,8 @@ Example of build replacing image: # result build: . -For the **multi-value options** `ports`, `expose`, `external_links`, `dns` and -`dns_search`, Compose concatenates both sets of values: +For the **multi-value options** `ports`, `expose`, `external_links`, `dns`, +`dns_search`, and `tmpfs`, Compose concatenates both sets of values: # original service expose: diff --git a/tests/integration/service_test.py b/tests/integration/service_test.py index bcb8733541f..1f0b0ca08b2 100644 --- a/tests/integration/service_test.py +++ b/tests/integration/service_test.py @@ -871,6 +871,11 @@ def test_dns_search(self): container = create_and_start_container(service) self.assertEqual(container.get('HostConfig.DnsSearch'), ['dc1.example.com', 'dc2.example.com']) + def test_tmpfs(self): + service = self.create_service('web', tmpfs=['/run']) + container = create_and_start_container(service) + self.assertEqual(container.get('HostConfig.Tmpfs'), {'/run': ''}) + def test_working_dir_param(self): service = self.create_service('container', working_dir='/working/dir/sample') container = service.create_container() diff --git a/tests/unit/config/config_test.py b/tests/unit/config/config_test.py index ce37d794f75..7b1b7b30cf9 100644 --- a/tests/unit/config/config_test.py +++ b/tests/unit/config/config_test.py @@ -1181,6 +1181,21 @@ def test_normalize_dns_options(self): } ] + def test_tmpfs_option(self): + actual = config.load(build_config_details({ + 'web': { + 'image': 'alpine', + 'tmpfs': '/run', + } + })) + assert actual.services == [ + { + 'name': 'web', + 'image': 'alpine', + 'tmpfs': ['/run'], + } + ] + def test_merge_service_dicts_from_files_with_extends_in_base(self): base = { 'volumes': ['.:/app'],