fix: failed to obtain container id

This commit is contained in:
DDSRem
2023-09-09 12:03:48 +08:00
parent 0136d9fe06
commit 42511b95d8

View File

@ -311,7 +311,11 @@ class SystemUtils:
# 创建 Docker 客户端
client = docker.DockerClient(base_url='tcp://127.0.0.1:38379')
# 获取当前容器的 ID
container_id = open("/proc/self/cgroup", "r").read().split("/")[-1]
container_hostname = os.environ.get("HOSTNAME")
if not container_hostname:
return False, "无法获取容器的主机名!"
container = client.containers.get(container_hostname)
container_id = container.id
if not container_id:
return False, "获取容器ID失败"
# 重启当前容器