Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docker/api/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def create_container(self, image, command=None, hostname=None, user=None,
cpu_shares=None, working_dir=None, domainname=None,
memswap_limit=None, cpuset=None, host_config=None,
mac_address=None, labels=None, volume_driver=None,
stop_signal=None, networking_config=None):
stop_signal=None, networking_config=None, tmpfs=None):

if isinstance(volumes, six.string_types):
volumes = [volumes, ]
Expand All @@ -114,7 +114,7 @@ def create_container(self, image, command=None, hostname=None, user=None,
tty, mem_limit, ports, environment, dns, volumes, volumes_from,
network_disabled, entrypoint, cpu_shares, working_dir, domainname,
memswap_limit, cpuset, host_config, mac_address, labels,
volume_driver, stop_signal, networking_config,
volume_driver, stop_signal, networking_config, tmpfs
)
return self.create_container_from_config(config, name)

Expand Down
18 changes: 17 additions & 1 deletion docker/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,7 @@ def create_container_config(
entrypoint=None, cpu_shares=None, working_dir=None, domainname=None,
memswap_limit=None, cpuset=None, host_config=None, mac_address=None,
labels=None, volume_driver=None, stop_signal=None, networking_config=None,
tmpfs=None
):
if isinstance(command, six.string_types):
command = split_command(command)
Expand All @@ -852,6 +853,11 @@ def create_container_config(
'stop_signal was only introduced in API version 1.21'
)

if tmpfs is not None and compare_version('1.22', version) < 0:
raise errors.InvalidVersion(
'tmpfs was only introduced in API version 1.22'
)

if compare_version('1.19', version) < 0:
if volume_driver is not None:
raise errors.InvalidVersion(
Expand Down Expand Up @@ -900,6 +906,15 @@ def create_container_config(
volumes_dict[vol] = {}
volumes = volumes_dict

if isinstance(tmpfs, six.string_types):
tmpfs = [tmpfs, ]

if isinstance(tmpfs, list):
tmpfs_dict = {}
for tmpdir in tmpfs:
tmpfs_dict[tmpdir] = ''
tmpfs = tmpfs_dict

if volumes_from:
if not isinstance(volumes_from, six.string_types):
volumes_from = ','.join(volumes_from)
Expand Down Expand Up @@ -958,5 +973,6 @@ def create_container_config(
'MacAddress': mac_address,
'Labels': labels,
'VolumeDriver': volume_driver,
'StopSignal': stop_signal
'StopSignal': stop_signal,
'Tmpfs': tmpfs
}
1 change: 1 addition & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ following format `["PASSWORD=xxx"]` or `{"PASSWORD": "xxx"}`.
* volumes (str or list):
* volumes_from (str or list): List of container names or Ids to get volumes
from. Optionally a single string joining container id's with commas
* tmpfs (str or list): Paths to mount tmpfs filesystems
* network_disabled (bool): Disable networking
* name (str): A name for the container
* entrypoint (str or list): An entrypoint
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/container_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,28 @@ def test_create_container_with_volume_string(self):
self.assertEqual(args[1]['headers'],
{'Content-Type': 'application/json'})

@requires_api_version('1.22')
def test_create_container_with_tmpfs(self):
tmpfs_dest = '/tmpdir'

self.client.create_container('busybox', ['ls', tmpfs_dest],
tmpfs=tmpfs_dest)

args = fake_request.call_args
self.assertEqual(args[0][1],
url_prefix + 'containers/create')
self.assertEqual(json.loads(args[1]['data']),
json.loads('''
{"Tty": false, "Image": "busybox",
"Cmd": ["ls", "/tmpdir"], "AttachStdin": false,
"Tmpfs": {"/tmpdir": ""},
"AttachStderr": true,
"AttachStdout": true, "OpenStdin": false,
"StdinOnce": false,
"NetworkDisabled": false}'''))
self.assertEqual(args[1]['headers'],
{'Content-Type': 'application/json'})

def test_create_container_with_ports(self):
self.client.create_container('busybox', 'ls',
ports=[1111, (2222, 'udp'), (3333,)])
Expand Down