From 42511b95d8d661dabfac02f74462a9cf952605f4 Mon Sep 17 00:00:00 2001 From: DDSRem <1448139087@qq.com> Date: Sat, 9 Sep 2023 12:03:48 +0800 Subject: [PATCH] fix: failed to obtain container id --- app/utils/system.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/utils/system.py b/app/utils/system.py index ca1b12cee..6e266234d 100644 --- a/app/utils/system.py +++ b/app/utils/system.py @@ -311,7 +311,11 @@ def restart() -> Tuple[bool, str]: # 创建 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失败!" # 重启当前容器