Unverified 提交 0b5ac224 authored 作者: Max Strobel's avatar Max Strobel 提交者: GitHub

fix: broken ``is_docker`` check (#8711)

Checking if ``/workspace`` exists is not a reliable method to check if the process runs in a docker container. Reusing the logic from the npm "is-docker" package to check if the process runs in a container. References: https://github.com/sindresorhus/is-docker/blob/main/index.js Fixes #8710. Co-authored-by: 's avatarMaximilian Strobel <Maximilian.Strobel@infineon.com> Co-authored-by: 's avatarGlenn Jocher <glenn.jocher@ultralytics.com>
上级 c775a296
...@@ -224,9 +224,15 @@ def get_latest_run(search_dir='.'): ...@@ -224,9 +224,15 @@ def get_latest_run(search_dir='.'):
return max(last_list, key=os.path.getctime) if last_list else '' return max(last_list, key=os.path.getctime) if last_list else ''
def is_docker(): def is_docker() -> bool:
# Is environment a Docker container? """Check if the process runs inside a docker container."""
return Path('/workspace').exists() # or Path('/.dockerenv').exists() if Path("/.dockerenv").exists():
return True
try: # check if docker is in control groups
with open("/proc/self/cgroup") as file:
return any("docker" in line for line in file)
except OSError:
return False
def is_colab(): def is_colab():
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论