@@ -154,25 +154,24 @@ def create_container(self, one_off=False, **override_options):
154154
155155 def recreate_containers (self , ** override_options ):
156156 """
157- If a container for this service doesn't exist, create one. If there are
158- any, stop them and create new ones. Does not remove the old containers.
157+ If a container for this service doesn't exist, create and start one. If there are
158+ any, stop them, create+start new ones, and remove the old containers.
159159 """
160160 containers = self .containers (stopped = True )
161161
162162 if len (containers ) == 0 :
163163 log .info ("Creating %s..." % self .next_container_name ())
164- return ([], [self .create_container (** override_options )])
164+ container = self .create_container (** override_options )
165+ self .start_container (container )
166+ return [(None , container )]
165167 else :
166- old_containers = []
167- new_containers = []
168+ tuples = []
168169
169170 for c in containers :
170171 log .info ("Recreating %s..." % c .name )
171- (old_container , new_container ) = self .recreate_container (c , ** override_options )
172- old_containers .append (old_container )
173- new_containers .append (new_container )
172+ tuples .append (self .recreate_container (c , ** override_options ))
174173
175- return ( old_containers , new_containers )
174+ return tuples
176175
177176 def recreate_container (self , container , ** override_options ):
178177 if container .is_running :
@@ -185,17 +184,20 @@ def recreate_container(self, container, **override_options):
185184 entrypoint = ['echo' ],
186185 command = [],
187186 )
188- intermediate_container .start ()
187+ intermediate_container .start (volumes_from = container . id )
189188 intermediate_container .wait ()
190189 container .remove ()
191190
192191 options = dict (override_options )
193192 options ['volumes_from' ] = intermediate_container .id
194193 new_container = self .create_container (** options )
194+ self .start_container (new_container , volumes_from = intermediate_container .id )
195+
196+ intermediate_container .remove ()
195197
196198 return (intermediate_container , new_container )
197199
198- def start_container (self , container = None , ** override_options ):
200+ def start_container (self , container = None , volumes_from = None , ** override_options ):
199201 if container is None :
200202 container = self .create_container (** override_options )
201203
@@ -228,6 +230,7 @@ def start_container(self, container=None, **override_options):
228230 links = self ._get_links (link_to_self = override_options .get ('one_off' , False )),
229231 port_bindings = port_bindings ,
230232 binds = volume_bindings ,
233+ volumes_from = volumes_from ,
231234 privileged = privileged ,
232235 )
233236 return container
0 commit comments