This guide walks you through adding Bollard to a new or existing Rust project, establishing a connection to your local Docker daemon, and making your first real API calls — listing running containers and streaming live container stats.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/fussybeaver/bollard/llms.txt
Use this file to discover all available pages before exploring further.
All Bollard API methods are
async and require a Tokio runtime. The examples below use the #[tokio::main] macro for simplicity. See the Installation page for the required tokio dependency and available feature flags.Add Bollard to Cargo.toml
Add
bollard and tokio to your project’s Cargo.toml. The default feature set (http + pipe) covers Unix sockets, Windows named pipes, and HTTP/TCP connections, which is all you need for local Docker access.Cargo.toml
Connect to Docker
Import Other connection methods are available depending on your environment:
bollard::Docker and call Docker::connect_with_local_defaults(). This method auto-detects the best available socket on your machine — the Unix socket on Linux/macOS or a Windows named pipe on Windows.src/main.rs
| Method | When to use |
|---|---|
Docker::connect_with_local_defaults() | Local socket / named pipe (recommended) |
Docker::connect_with_podman_defaults() | Rootless or system Podman (Unix only) |
Docker::connect_with_socket_defaults() | Explicit Unix socket or named pipe |
Docker::connect_with_http_defaults() | Remote daemon over plain HTTP/TCP |
Docker::connect_with_ssl_defaults() | Remote daemon over HTTPS (requires ssl feature) |
Verify the Connection with docker.version()
Call A successful run prints something like:
docker.version().await to confirm the connection is working and print the daemon’s API version.src/main.rs
You can also call
docker.negotiate_version().await to automatically downgrade the client to the API version your daemon actually supports, which is useful when connecting to older Docker or Podman instances.List Running Containers
Use
docker.list_containers() with a ListContainersOptionsBuilder to query the daemon for running containers. Filters are passed as a HashMap<String, Vec<String>>.src/main.rs
list_containers returns a Vec<ContainerSummary> from bollard::models. Each ContainerSummary contains fields like id, names, image, state, status, ports, and labels.Stream Container Stats
docker.stats() returns a Stream of Stats values. Use futures_util::stream::TryStreamExt to collect or process items as they arrive. Pass .stream(true) to keep the stream open; pass .stream(false) to get a single snapshot.src/main.rs
.try_next() instead of collecting:src/main.rs
What’s Next
You now have a working Bollard setup that can connect to a Docker daemon, inspect running containers, and consume streaming stats. From here you can explore the full API surface:bollard::container— create, start, stop, attach, wait, and remove containersbollard::image— pull, build, tag, and push imagesbollard::exec— run commands inside a running container (see the exec example)bollard::network/bollard::volume— manage networks and volumesbollard::service/bollard::swarm— orchestrate with Docker Swarm
