Skip to content

Commit 5a33900

Browse files
committed
debug: report on exec?
1 parent 79bd0ae commit 5a33900

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

pythonbuild/docker.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,21 @@ def run_container(client, image):
139139
def 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:

0 commit comments

Comments
 (0)