15
15
log = logging .getLogger (__name__ )
16
16
17
17
18
- DOCKER_CONFIG_KEYS = ['image' , 'command' , 'hostname' , 'domainname' , 'user' , 'detach' , 'stdin_open' , 'tty' , 'mem_limit' , 'ports' , 'environment' , 'dns' , 'volumes' , 'entrypoint' , 'privileged' , 'volumes_from' , 'net' , 'working_dir' ]
18
+ DOCKER_CONFIG_KEYS = ['image' , 'command' , 'hostname' , 'domainname' , 'user' , 'detach' , 'stdin_open' , 'tty' , 'mem_limit' , 'ports' , 'environment' , 'dns' , 'volumes' , 'entrypoint' , 'privileged' , 'volumes_from' , 'net' , 'working_dir' , 'restart' ]
19
19
DOCKER_CONFIG_HINTS = {
20
20
'link' : 'links' ,
21
21
'port' : 'ports' ,
@@ -262,6 +262,8 @@ def start_container(self, container=None, intermediate_container=None, **overrid
262
262
net = options .get ('net' , 'bridge' )
263
263
dns = options .get ('dns' , None )
264
264
265
+ restart = parse_restart_spec (options .get ('restart' , None ))
266
+
265
267
container .start (
266
268
links = self ._get_links (link_to_self = options .get ('one_off' , False )),
267
269
port_bindings = port_bindings ,
@@ -270,6 +272,7 @@ def start_container(self, container=None, intermediate_container=None, **overrid
270
272
privileged = privileged ,
271
273
network_mode = net ,
272
274
dns = dns ,
275
+ restart_policy = restart
273
276
)
274
277
return container
275
278
@@ -376,7 +379,7 @@ def _get_container_create_options(self, override_options, one_off=False):
376
379
container_options ['image' ] = self ._build_tag_name ()
377
380
378
381
# Delete options which are only used when starting
379
- for key in ['privileged' , 'net' , 'dns' ]:
382
+ for key in ['privileged' , 'net' , 'dns' , 'restart' ]:
380
383
if key in container_options :
381
384
del container_options [key ]
382
385
@@ -466,6 +469,22 @@ def get_container_name(container):
466
469
return name [1 :]
467
470
468
471
472
+ def parse_restart_spec (restart_config ):
473
+ if not restart_config :
474
+ return None
475
+ parts = restart_config .split (':' )
476
+ if len (parts ) > 2 :
477
+ raise ConfigError ("Restart %s has incorrect format, should be "
478
+ "mode[:max_retry]" % restart_config )
479
+ if len (parts ) == 2 :
480
+ name , max_retry_count = parts
481
+ else :
482
+ name , = parts
483
+ max_retry_count = 0
484
+
485
+ return {'Name' : name , 'MaximumRetryCount' : int (max_retry_count )}
486
+
487
+
469
488
def parse_volume_spec (volume_config ):
470
489
parts = volume_config .split (':' )
471
490
if len (parts ) > 3 :
0 commit comments