Skip to content

Commit

Permalink
Fix docker id infer
Browse files Browse the repository at this point in the history
  • Loading branch information
Wh1isper committed Nov 29, 2023
1 parent 2978b81 commit 40b6b76
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 4 additions & 4 deletions duetector/injectors/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class DockerInjector(ProcInjector, Inspector):
def __init__(self, config: dict[str, Any] = None, *args, **kwargs):
super().__init__(config, *args, **kwargs)
try:
# TODO: Config docker base_url and tls
self.client = docker.APIClient()
if not self.client.ping():
self.client = None
Expand Down Expand Up @@ -42,14 +43,13 @@ def _inspect(self, model: dict[str, Any]) -> dict[str, Any]:
return {}
container_id = None
for cg in cgroups:
if "docker" in cg:
container_id = cg.split(":")[-1].split("/")[-1].lstrip("docker-").split(".")[0]
break
container_id = cg.split(":")[-1].split("/")[-1].lstrip("docker-").split(".")[0]
break
if not container_id:
return {}

if not self.client:
return {"container_id": container_id}
return {"maybe_container_id": container_id}
try:
container_info = self.client.inspect_container(container_id)
except Exception as e:
Expand Down
6 changes: 6 additions & 0 deletions tests/base/injector/test_docker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import glob
import time
from collections import namedtuple
from pathlib import Path

Expand Down Expand Up @@ -37,6 +38,11 @@ def test_container(docker_client: docker.DockerClient, command: str):
detach=True,
remove=True,
)
container.reload()
while container.status != "running":
container.reload()
time.sleep(0.5)

pid = None
for p in glob.glob("/proc/[0-9]*"):
p = Path(p)
Expand Down

0 comments on commit 40b6b76

Please sign in to comment.