@@ -378,10 +378,21 @@ def create_host_config(
378
378
dns = None , dns_search = None , volumes_from = None , network_mode = None ,
379
379
restart_policy = None , cap_add = None , cap_drop = None , devices = None ,
380
380
extra_hosts = None , read_only = None , pid_mode = None , ipc_mode = None ,
381
- security_opt = None , ulimits = None , log_config = None
381
+ security_opt = None , ulimits = None , log_config = None , mem_limit = None ,
382
+ memswap_limit = None
382
383
):
383
384
host_config = {}
384
385
386
+ if mem_limit is not None :
387
+ if isinstance (mem_limit , six .string_types ):
388
+ mem_limit = parse_bytes (mem_limit )
389
+ host_config ['Memory' ] = mem_limit
390
+
391
+ if memswap_limit is not None :
392
+ if isinstance (memswap_limit , six .string_types ):
393
+ memswap_limit = parse_bytes (memswap_limit )
394
+ host_config ['MemorySwap' ] = memswap_limit
395
+
385
396
if pid_mode not in (None , 'host' ):
386
397
raise errors .DockerException (
387
398
'Invalid value for pid param: {0}' .format (pid_mode )
@@ -498,10 +509,10 @@ def create_host_config(
498
509
499
510
def create_container_config (
500
511
version , image , command , hostname = None , user = None , detach = False ,
501
- stdin_open = False , tty = False , mem_limit = 0 , ports = None , environment = None ,
512
+ stdin_open = False , tty = False , mem_limit = None , ports = None , environment = None ,
502
513
dns = None , volumes = None , volumes_from = None , network_disabled = False ,
503
514
entrypoint = None , cpu_shares = None , working_dir = None , domainname = None ,
504
- memswap_limit = 0 , cpuset = None , host_config = None , mac_address = None ,
515
+ memswap_limit = None , cpuset = None , host_config = None , mac_address = None ,
505
516
labels = None , volume_driver = None
506
517
):
507
518
if isinstance (command , six .string_types ):
@@ -517,10 +528,24 @@ def create_container_config(
517
528
'labels were only introduced in API version 1.18'
518
529
)
519
530
520
- if volume_driver is not None and compare_version ('1.19' , version ) < 0 :
521
- raise errors .InvalidVersion (
522
- 'Volume drivers were only introduced in API version 1.19'
523
- )
531
+ if compare_version ('1.19' , version ) < 0 :
532
+ if volume_driver is not None :
533
+ raise errors .InvalidVersion (
534
+ 'Volume drivers were only introduced in API version 1.19'
535
+ )
536
+ mem_limit = mem_limit if mem_limit is not None else 0
537
+ memswap_limit = memswap_limit if memswap_limit is not None else 0
538
+ else :
539
+ if mem_limit is not None :
540
+ raise errors .InvalidVersion (
541
+ 'mem_limit has been moved to host_config in API version 1.19'
542
+ )
543
+
544
+ if memswap_limit is not None :
545
+ raise errors .InvalidVersion (
546
+ 'memswap_limit has been moved to host_config in API '
547
+ 'version 1.19'
548
+ )
524
549
525
550
if isinstance (labels , list ):
526
551
labels = dict ((lbl , six .text_type ('' )) for lbl in labels )
0 commit comments