File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 88import os
99import pathlib
1010import tarfile
11+ import time
1112
1213import docker # type: ignore
1314import jinja2
@@ -109,6 +110,25 @@ def run_container(client, image):
109110 container = client .containers .run (
110111 image , command = ["/bin/sleep" , "86400" ], detach = True
111112 )
113+
114+ # Check if container is actually running
115+ for _ in range (10 ):
116+ container .reload ()
117+
118+ if container .status in ("created" , "starting" ):
119+ time .sleep (1 )
120+ continue
121+
122+ if container .status == "running" :
123+ break
124+
125+ state = container .attrs .get ("State" , {})
126+ exit_code = state .get ("ExitCode" )
127+ error = state .get ("Error" , "" )
128+ raise RuntimeError (
129+ f"Container failed to start (status { container .status } ) with exit code { exit_code } : { error } "
130+ )
131+
112132 try :
113133 yield container
114134 finally :
You can’t perform that action at this time.
0 commit comments