Skip to content

Commit

Permalink
fix: #21 Updated function to get container id to work with cgroups v2.
Browse files Browse the repository at this point in the history
  • Loading branch information
vogoltsov committed Oct 31, 2022
1 parent cb1aca8 commit f7edb03
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/DockerComposeLibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,5 +525,9 @@ def _get_container_gateway_ip(self) -> str:
@staticmethod
def _get_container_id() -> str:
"""Helper function to retrieve current Docker container id."""
with open('/proc/1/cpuset', 'r', encoding=sys.getdefaultencoding()) as file:
return file.read().rstrip().split('/')[2]
with open('/proc/self/mountinfo', 'r', encoding=sys.getdefaultencoding()) as file:
for line in iter(file.readline, b''):
if '/docker/containers/' not in line:
continue
return line.split('/docker/containers/')[-1].split('/')[0]
raise AssertionError('Failed to obtain container id')

0 comments on commit f7edb03

Please sign in to comment.