Skip to content

Commit 79bd0ae

Browse files
committed
debug: Check if the container is running on start
1 parent 9c28b1b commit 79bd0ae

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pythonbuild/docker.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import os
99
import pathlib
1010
import tarfile
11+
import time
1112

1213
import docker # type: ignore
1314
import 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:

0 commit comments

Comments
 (0)