Skip to main content

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.

Bollard provides first-class support for connecting to a locally running Docker daemon. On Linux and macOS it communicates over a Unix domain socket; on Windows it uses a Named Pipe. The helper methods below abstract away the platform difference so most code can be written once and run anywhere.

Auto-detect the Best Local Connection

Docker::connect_with_local_defaults() is the recommended starting point for local connections. On Unix it delegates to connect_with_unix_defaults; on Windows it delegates to connect_with_named_pipe_defaults. Both variants respect the Docker CLI precedence for host resolution (DOCKER_HOST env var → DOCKER_CONTEXT env var → currentContext in ~/.docker/config.json → platform default).
use bollard::Docker;

let docker = Docker::connect_with_local_defaults().unwrap();
Use Docker::connect_with_local when you need to supply an explicit socket path, timeout, or API version:
use bollard::{API_DEFAULT_VERSION, Docker};

// Unix
let docker = Docker::connect_with_local(
    "unix:///var/run/docker.sock",
    120,
    API_DEFAULT_VERSION,
).unwrap();

Function signatures

// Delegates to connect_with_unix_defaults() on Unix,
// connect_with_named_pipe_defaults() on Windows.
pub fn connect_with_local_defaults() -> Result<Docker, Error>

// Delegates to connect_with_unix() on Unix,
// connect_with_named_pipe() on Windows.
pub fn connect_with_local(
    addr: &str,
    timeout: u64,
    client_version: &ClientVersion,
) -> Result<Docker, Error>
Both methods require the pipe feature flag, which is enabled by default. If you have disabled default features, add features = ["pipe"] to your Cargo.toml dependency.

Unix Socket (Linux / macOS)

connect_with_socket_defaults

Connects to the standard Unix socket path /var/run/docker.sock (or //./pipe/docker_engine on Windows). This is a cross-platform convenience wrapper around connect_with_unix / connect_with_named_pipe.
use bollard::Docker;

let docker = Docker::connect_with_socket_defaults().unwrap();

connect_with_socket

Parameterised variant — supply any Unix socket path, a timeout in seconds, and an API ClientVersion.
use bollard::{API_DEFAULT_VERSION, Docker};

let docker = Docker::connect_with_socket(
    "/var/run/docker.sock",
    120,
    API_DEFAULT_VERSION,
).unwrap();

Function signatures

pub fn connect_with_socket_defaults() -> Result<Docker, Error>

pub fn connect_with_socket(
    path: &str,
    timeout: u64,
    client_version: &ClientVersion,
) -> Result<Docker, Error>

connect_with_unix_defaults / connect_with_unix

Lower-level Unix-only methods. connect_with_unix_defaults resolves the host using the Docker CLI precedence chain before falling back to DEFAULT_SOCKET.
use bollard::{API_DEFAULT_VERSION, Docker};

// Defaults — respects DOCKER_HOST / context / config.json
let docker = Docker::connect_with_unix_defaults().unwrap();

// Explicit path
let docker = Docker::connect_with_unix(
    "/var/run/docker.sock",
    120,
    API_DEFAULT_VERSION,
).unwrap();

Function signatures

pub fn connect_with_unix_defaults() -> Result<Docker, Error>

pub fn connect_with_unix(
    path: &str,
    timeout: u64,
    client_version: &ClientVersion,
) -> Result<Docker, Error>

Windows Named Pipe

connect_with_named_pipe_defaults

Connects to the standard Windows named pipe //./pipe/docker_engine. Respects the Docker CLI host-resolution precedence; falls back to DEFAULT_NAMED_PIPE when the resolved host is not an npipe:// address.
use bollard::Docker;

let docker = Docker::connect_with_named_pipe_defaults().unwrap();

connect_with_named_pipe

Parameterised variant for custom pipe paths.
use bollard::{API_DEFAULT_VERSION, Docker};

let docker = Docker::connect_with_named_pipe(
    "//./pipe/docker_engine",
    120,
    API_DEFAULT_VERSION,
).unwrap();

Function signatures

pub fn connect_with_named_pipe_defaults() -> Result<Docker, Error>

pub fn connect_with_named_pipe(
    path: &str,
    timeout: u64,
    client_version: &ClientVersion,
) -> Result<Docker, Error>

Constants

The following public constants define the default addresses used by the connection helpers:
ConstantPlatformValue
DEFAULT_SOCKETUnix"unix:///var/run/docker.sock"
DEFAULT_NAMED_PIPEWindows"npipe:////./pipe/docker_engine"
DEFAULT_DOCKER_HOSTUnixalias of DEFAULT_SOCKET
DEFAULT_DOCKER_HOSTWindowsalias of DEFAULT_NAMED_PIPE
use bollard::{DEFAULT_SOCKET, DEFAULT_DOCKER_HOST};

// On Unix:
// DEFAULT_SOCKET        == "unix:///var/run/docker.sock"
// DEFAULT_DOCKER_HOST   == "unix:///var/run/docker.sock"

Feature Flags

pipe (default)

Enables Unix socket and Windows named pipe transports. Required by all connection methods on this page. Included in the default feature set — no extra configuration needed for most projects.

Minimal binary

To reduce binary size, disable default features and re-enable only what you need:
bollard = { version = "*", default-features = false, features = ["pipe"] }

Complete Example

1

Add Bollard to Cargo.toml

[dependencies]
bollard = "*"          # pipe + http enabled by default
tokio = { version = "1", features = ["full"] }
2

Connect and verify

use bollard::Docker;

#[tokio::main]
async fn main() {
    let docker = Docker::connect_with_local_defaults()
        .expect("Failed to connect to local Docker daemon");

    let version = docker.version().await.unwrap();
    println!("Docker version: {:?}", version.version);
}

Build docs developers (and LLMs) love