Skip to content

Commit 7edb0e9

Browse files
committed
Fix Docker container ID detection on cgroup v2
Use an alternative newer hack for finding the current docker container ID for the network mode detection (for Airbyte/dbt) containers. Credit: https://stackoverflow.com/a/71823877
1 parent fe859a7 commit 7edb0e9

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

splitgraph/ingestion/airbyte/docker_utils.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,17 @@ def detect_network_mode() -> str:
8181
# receiver with net:host. Inside Docker we have to use the host's Docker socket and
8282
# attach the container to our own network so that it can also use our own params.
8383

84+
# Credit: https://stackoverflow.com/a/71823877
85+
8486
# This also applies in case we're running a source against a database that's also running
8587
# in Docker -- we want to mimic sgr too.
8688
if os.path.exists("/.dockerenv"):
87-
with open("/proc/1/cgroup", "r") as f:
88-
match = re.search(r"^.*/docker/([0-9a-f]{64})$", f.read(), re.MULTILINE)
89+
with open("/proc/self/mountinfo", "r") as f:
90+
match = re.search(
91+
r"^.*/containers/([0-9a-f]{64})/.*$",
92+
f.read(),
93+
re.MULTILINE,
94+
)
8995
if not match:
9096
raise AssertionError("Could not detect Docker container ID")
9197
return f"container:{match.group(1)}"

0 commit comments

Comments
 (0)