MCPcopy Create free account
hub / github.com/Louisym/MiniCC / demo_container_detection

Function demo_container_detection

tutorials/14_bash_engine_deep_dive.py:818–841  ·  view source on GitHub ↗

演示容器环境检测

()

Source from the content-addressed store, hash-verified

816
817
818def demo_container_detection():
819 """演示容器环境检测"""
820 print("\n" + "=" * 60)
821 print("容器环境检测")
822 print("=" * 60)
823
824 result = detect_container_environment()
825 print(f"当前环境是容器: {result.in_container}")
826 if result.markers:
827 print(f"检测到的标记: {result.markers}")
828 else:
829 print("未检测到任何容器标记(在宿主机上运行)")
830
831 # 模拟各种容器环境
832 print("\n模拟不同容器环境的检测结果:")
833 simulated = [
834 ("Docker", {"标记": ["/.dockerenv", "env:DOCKER=1"]}),
835 ("Kubernetes", {"标记": ["env:KUBERNETES_SERVICE_HOST=10.0.0.1"]}),
836 ("Podman", {"标记": ["/run/.containerenv"]}),
837 ("裸机", {"标记": []}),
838 ]
839 for env_name, info in simulated:
840 is_container = len(info["标记"]) > 0
841 print(f" {env_name}: in_container={is_container}, markers={info['标记']}")
842
843
844# ============================================================

Callers 1

Calls 1

Tested by

no test coverage detected