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 can reach a remote Docker daemon over a plain HTTP/TCP connection. This is the simplest way to talk to a Docker host that has been configured to listen on a TCP port, and it is also the transport used when DOCKER_HOST is set to a tcp:// or http:// address.
Plain HTTP transmits all Docker API traffic — including image layers, secrets passed as build arguments, and container exec payloads — in clear text. Use this transport only on trusted private networks or loopback. For any public or shared network, use SSL/TLS instead.

Docker::connect_with_http_defaults

Reads the DOCKER_HOST environment variable to determine the target address. If the variable is not set, it falls back to tcp://localhost:2375.
use bollard::Docker;

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

Function signature

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

How the address is resolved

  1. Read DOCKER_HOST from the environment.
  2. If unset, use DEFAULT_TCP_ADDRESS ("tcp://localhost:2375").
  3. Strip the tcp:// or http:// scheme prefix before handing the address to Hyper.

Docker::connect_with_http

Use this when you need to specify the remote address, a custom timeout, or a specific API version at call time.
use bollard::{API_DEFAULT_VERSION, Docker};

let docker = Docker::connect_with_http(
    "tcp://192.168.1.100:2375",
    120,
    API_DEFAULT_VERSION,
).unwrap();

Function signature

pub fn connect_with_http(
    addr: &str,
    timeout: u64,
    client_version: &ClientVersion,
) -> Result<Docker, Error>
ParameterTypeDescription
addr&strConnection URL — tcp:// or http:// scheme with host and port.
timeoutu64Read/write timeout in seconds (default helpers use 120).
client_version&ClientVersionDocker API version to request. Use API_DEFAULT_VERSION for the latest supported version.

Docker::connect_with_host

A higher-level dispatcher that selects the correct transport based on the URL scheme. For tcp:// and http:// addresses it routes to connect_with_http (and will automatically upgrade to SSL if DOCKER_TLS_VERIFY is set and the ssl feature is enabled).
use bollard::Docker;

let docker = Docker::connect_with_host("tcp://docker.example.com:2375").unwrap();

Function signature

pub fn connect_with_host(host: &str) -> Result<Docker, Error>
connect_with_host also dispatches unix://, npipe://, https://, and ssh:// schemes to the appropriate connector, making it useful as a single entry point when the transport is determined at runtime.

Environment Variables

VariableDescription
DOCKER_HOSTFull URL of the Docker daemon. Examples: tcp://localhost:2375, http://192.168.1.10:2375. Accepted by both connect_with_http_defaults and connect_with_host.

Constants

use bollard::DEFAULT_TCP_ADDRESS;

// DEFAULT_TCP_ADDRESS == "tcp://localhost:2375"
ConstantValue
DEFAULT_TCP_ADDRESS"tcp://localhost:2375"

Feature Flag

The HTTP connector requires the http feature, which is enabled by default. If you have disabled default features, add it explicitly:
bollard = { version = "*", default-features = false, features = ["http"] }

Complete Example

1

Configure the Docker daemon for TCP (server side)

Edit /etc/docker/daemon.json on the remote host and add a TCP listener. Restart Docker after saving.
{
  "hosts": ["unix:///var/run/docker.sock", "tcp://0.0.0.0:2375"]
}
2

Add Bollard to Cargo.toml

[dependencies]
bollard = "*"
tokio = { version = "1", features = ["full"] }
3

Connect from your Rust application

use bollard::Docker;

#[tokio::main]
async fn main() {
    // Explicit address
    let docker = Docker::connect_with_http(
        "tcp://192.168.1.100:2375",
        120,
        &bollard::API_DEFAULT_VERSION,
    )
    .expect("Failed to connect");

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

Or use the environment variable

export DOCKER_HOST=tcp://192.168.1.100:2375
cargo run
use bollard::Docker;

#[tokio::main]
async fn main() {
    // Reads DOCKER_HOST automatically
    let docker = Docker::connect_with_http_defaults()
        .expect("Failed to connect");

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

Build docs developers (and LLMs) love