File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -139,10 +139,21 @@ def run_container(client, image):
139139def container_exec (container , command , user = "build" , environment = None ):
140140 # docker-py's exec_run() won't return the exit code. So we reinvent the
141141 # wheel.
142- create_res = container .client .api .exec_create (
143- container .id , command , user = user , environment = environment
144- )
145-
142+ try :
143+ create_res = container .client .api .exec_create (
144+ container .id , command , user = user , environment = environment
145+ )
146+ except Exception as exc :
147+ if container .status != "running" :
148+ state = container .attrs .get ("State" , {})
149+ exit_code = state .get ("ExitCode" )
150+ error = state .get ("Error" , "" )
151+ raise RuntimeError (
152+ f"Container is not running (status { container .status } ) with exit code { exit_code } : { error } "
153+ ) from exc
154+ else :
155+ raise
156+
146157 exec_output = container .client .api .exec_start (create_res ["Id" ], stream = True )
147158
148159 for chunk in exec_output :
You can’t perform that action at this time.
0 commit comments