Skip to content

Commit 019468d

Browse files
committed
Adding units specification to mem_limit variable
1 parent 14f9c07 commit 019468d

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ more information on how to create port bindings and volume mappings.
8181
The `environment` variable accepts a dictionary or a list of strings
8282
in the following format `["PASSWORD=xxx"]` or `{"PASSWORD": "xxx"}`.
8383

84+
The `mem_limit` variable accepts float values (which represent the memory limit of the created container in bytes) or a string with a units identification char ('1000k', 128m', '1g').
85+
8486
`volumes_from` and `dns` arguments raise TypeError exception if they are used
8587
against v1.10 of docker remote API. Those arguments should be passed to
8688
`start()` instead.

docker/client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ def _container_config(self, image, command, hostname=None, user=None,
111111
'{0}={1}'.format(k, v) for k, v in environment.items()
112112
]
113113

114+
if isinstance(mem_limit, six.string_types):
115+
units = {'k': 1024,
116+
'm': 1024*1024,
117+
'g': 1024*1024*1024}
118+
suffix = mem_limit[-1].lower()
119+
if suffix in units.keys():
120+
mem_limit = int(mem_limit[:-1]) * units[suffix]
121+
114122
if isinstance(ports, list):
115123
exposed_ports = {}
116124
for port_definition in ports:

0 commit comments

Comments
 (0)