docker_utils
Docker host helpers: client access, self-inspection, GPUs and images.
Everything that talks to the Docker daemon outside of a launch goes through this module so the rest of the server never creates its own client.
attributelogger= logging.getLogger(__name__)funcget_docker_client() -> docker.DockerClientReturn the shared Docker client, creating it on first use.
Returns
docker.DockerClientA DockerClient connected from the environment.
funccontainer_exists(instance_id) -> boolTell whether a container still exists on the host.
paraminstance_idstrContainer id.
Returns
boolTrue if Docker knows the container, False if it is gone.
funcprune_dangling_images() -> NoneRemove dangling images left behind by pulls.
Returns
Nonefuncinspect_self_container() -> NoneDiscover mount mappings, ports and network of the server's own container.
Populates state.path_prefix_map, state.discovered_api_port,
state.discovered_session_port and state.discovered_network. When
the server is not running inside Docker nothing is changed.
Returns
Nonefunctranslate_path_to_host(internal_path) -> strMap a path inside the server container to the equivalent host path.
paraminternal_pathstrAbsolute path as seen by the server process.
Returns
strThe host path when a mount prefix matches, otherwise the input.
funcread_cpu_model() -> NoneRead the CPU model name from /proc/cpuinfo into state.cpu_model.
Returns
Nonefuncget_system_stats() -> dict[str, Any]Return CPU model and storage usage, cached for one minute.
Returns
dictDictionary with cpu_model, disk_total and disk_used.
funcdetect_gpus() -> NoneDetect render nodes under /sys/class/drm into state.available_gpus.
Returns
Nonefuncget_and_cache_image_metadata(image_name, force_refresh=False) -> NoneRecord the local digest of an image in state.image_metadata.
paramimage_namestrImage reference such as ghcr.io/org/app:latest.
paramforce_refreshbool= FalseRe-query Docker even when a digest is cached.
Returns
Nonefuncpull_and_cache_image(image_name) -> NonePull an image in the background and refresh its cached digest.
paramimage_namestrImage reference to pull.
Returns
None