@@ -202,10 +202,9 @@ def start(self) -> Self:
202202 else {}
203203 )
204204
205- self ._container = docker_client .run (
205+ self ._container = docker_client .create (
206206 self .image ,
207207 command = self ._command ,
208- detach = True ,
209208 environment = self .env ,
210209 ports = cast ("dict[int, Optional[int]]" , self .ports ),
211210 name = self ._name ,
@@ -214,14 +213,16 @@ def start(self) -> Self:
214213 ** {** network_kwargs , ** self ._kwargs },
215214 )
216215
216+ for t in self ._transferable_specs :
217+ self ._transfer_into_container (* t )
218+
219+ docker_client .start (self ._container )
220+
217221 if self ._wait_strategy is not None :
218222 self ._wait_strategy .wait_until_ready (self )
219223
220224 logger .info ("Container started: %s" , self ._container .short_id )
221225
222- for t in self ._transferable_specs :
223- self ._transfer_into_container (* t )
224-
225226 return self
226227
227228 def stop (self , force : bool = True , delete_volume : bool = True ) -> None :
@@ -328,6 +329,13 @@ def exec(self, command: Union[str, list[str]]) -> ExecResult:
328329 raise ContainerStartException ("Container should be started before executing a command" )
329330 return self ._container .exec_run (command )
330331
332+ def wait (self ) -> int :
333+ """Wait for the container to stop and return its exit code."""
334+ if not self ._container :
335+ raise ContainerStartException ("Container should be started before waiting" )
336+ result = self ._container .wait ()
337+ return int (result ["StatusCode" ])
338+
331339 def _configure (self ) -> None :
332340 # placeholder if subclasses want to define this and use the default start method
333341 pass
0 commit comments