Skip to main content

Crate nanodock

Crate nanodock 

Source
Expand description

§nanodock

Zero-dependency-light Docker/Podman daemon client for container detection, port mapping, and lifecycle control.

§Module structure

  • api - JSON response parsing and container name resolution.
  • http - Minimal HTTP/1.0 response parser (headers via httparse).
  • ipc - OS-specific transport (Unix socket, Windows named pipe, TCP).
  • podman - Rootless Podman resolver via overlay metadata (Linux only).

§Quick start

§Best-effort path (background thread, never errors)

use nanodock::{start_detection, await_detection};

let handle = start_detection(None);
// ... do other work while detection runs in the background ...
let port_map = await_detection(handle);
for ((ip, port, proto), info) in &port_map {
    println!("{proto} port {port} -> {} ({})", info.name, info.image);
}

§Strict path (synchronous, returns errors)

use nanodock::detect_containers;

match detect_containers(None) {
    Ok(port_map) => {
        for ((ip, port, proto), info) in &port_map {
            println!("{proto} port {port} -> {} ({})", info.name, info.image);
        }
    }
    Err(e) => eprintln!("detection failed: {e}"),
}

Structs§

ContainerInfo
Metadata about a running container that has published ports.
DetectionHandle
Handle for an in-progress Docker/Podman container detection.
RootlessPodmanResolver
Cache for rootless Podman container lookups keyed by process and network namespace.

Enums§

Error
Error returned by detect_containers when the daemon cannot be reached or returns an unusable response.
Protocol
Network transport protocol.
PublishedContainerMatch
Result of matching a socket against published container port bindings.
StopOutcome
Result of attempting to stop or kill a container via the daemon API.

Functions§

await_detection
Wait for Docker/Podman detection to complete.
detect_containers
Synchronously detect Docker/Podman containers and their published ports.
is_podman_rootlessport_process
Check whether a process name matches the Podman rootless port-forwarder.
lookup_published_container
Match a local socket against known published container bindings.
lookup_rootless_podman_container
Resolve a rootless Podman rootlessport helper process back to its container.
parse_containers_json
Parse the JSON response from GET /containers/json into a port map.
parse_containers_json_strict
Strict variant of parse_containers_json that propagates JSON deserialization errors instead of silently returning an empty map.
short_container_id
Truncate a full container ID to its 12-character short form.
start_detection
Start asynchronous detection of Docker/Podman containers.
stop_container
Stop or kill a running container via the Docker/Podman daemon API.

Type Aliases§

ContainerPortMap
Maps (host_ip, host_port, protocol) to container info.