Skip to content

Commit

Permalink
Merge pull request #520 from DDS-Derek/main
Browse files Browse the repository at this point in the history
fix: failed to obtain container id
  • Loading branch information
jxxghp authored Sep 9, 2023
2 parents b18e901 + 42511b9 commit 482fca9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/utils/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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失败!"
# 重启当前容器
Expand Down

0 comments on commit 482fca9

Please sign in to comment.