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.

Every fallible Bollard method returns Result<T, bollard::errors::Error>. The Error type is a #[non_exhaustive] enum derived from the thiserror crate, so each variant implements std::error::Error and provides a human-readable Display message automatically.
use bollard::errors::Error;
The enum is marked #[non_exhaustive], which means new variants may be added in future releases without a breaking change. Always include a catch-all _ => arm in your match expressions.

API and stream error variants

These are the variants you will encounter most often during normal operation.

DockerResponseServerError

The Docker daemon returned an HTTP error status code.
Error::DockerResponseServerError {
    status_code: u16,
    message: String,
}
FieldDescription
status_codeHTTP status code from the daemon (e.g. 404, 409, 500).
messageThe error body returned by the daemon.
Display: Docker responded with status code {status_code}: {message}

JsonDataError

JSON deserialization of a daemon response failed. This usually indicates an API version mismatch or an unexpected response shape.
Error::JsonDataError {
    message: String,
    column: usize,
    // Only present with the `json_data_content` feature:
    // contents: String,
}
FieldDescription
messageShort excerpt of the JSON near the parse error.
columnCharacter offset within the JSON where the error was detected.
Display: Failed to deserialize JSON: {message}
Enable the json_data_content Cargo feature to add a contents: String field that captures the full raw JSON payload, making it much easier to diagnose unexpected daemon responses:
bollard = { version = "*", features = ["json_data_content"] }

RequestTimeoutError

The request did not complete within the configured timeout duration.
Error::RequestTimeoutError
Display: Timeout error

DockerStreamError

An error message was emitted mid-stream during a streaming operation (e.g. during image build, pull, or push). The overall HTTP response was successful, but the stream payload contained an error event.
Error::DockerStreamError {
    error: String,
}
FieldDescription
errorThe error string emitted within the stream payload.
Display: Docker stream error: {error}

DockerContainerWaitError

Returned by wait_container when a container exits with a non-zero status or the wait call itself encounters an error.
Error::DockerContainerWaitError {
    error: String,
    code: i64,
}
FieldDescription
errorThe error string returned from the container wait response.
codeThe exit code of the container.
Display: Docker container wait error: {error}

APIVersionParseError

The Docker API version string returned by the daemon could not be parsed.
Error::APIVersionParseError {}
Display: Failed to parse API version

MissingSessionBuildkitError

A BuildKit operation was attempted without a session ID.
Error::MissingSessionBuildkitError {}
Display: Buildkit requires a unique session

MissingVersionBuildkitError

A BuildKit operation was attempted without the builder version being set.
Error::MissingVersionBuildkitError {}
Display: Buildkit requires a builder version set

SSL/TLS error variants

These variants are only present when the ssl_providerless Cargo feature is enabled.

NoHomePathError

The DOCKER_CERT_PATH environment variable was set but no home directory could be determined.
#[cfg(feature = "ssl_providerless")]
Error::NoHomePathError
Display: Could not find home directory

CertPathError

A certificate file could not be opened or read.
#[cfg(feature = "ssl_providerless")]
Error::CertPathError { path: PathBuf }
Display: Cannot open/read certificate with path: {path}

CertMultipleKeys

A certificate file contained more than one private key.
#[cfg(feature = "ssl_providerless")]
Error::CertMultipleKeys { count: usize, path: PathBuf }
Display: Found multiple keys ({count}), expected one: {path}

CertParseError

A private key in a certificate file could not be parsed (e.g. an RSA-encrypted key).
#[cfg(feature = "ssl_providerless")]
Error::CertParseError { path: PathBuf }
Display: Could not parse key: {path}

NoNativeCertsError

A native PKI certificate could not be parsed during TLS setup.
#[cfg(feature = "ssl_providerless")]
Error::NoNativeCertsError { err: rustls::Error }
Display: Could not parse a pki native cert

LoadNativeCertsErrors

One or more errors occurred while loading native certificates for TLS.
#[cfg(feature = "ssl_providerless")]
Error::LoadNativeCertsErrors { errors: Vec<rustls_native_certs::Error> }
Display: Could not load native certs

Transparent / wrapped error variants

These wrap underlying library errors transparently. Their Display output and source chain are forwarded from the inner error.
VariantInner typeTypical cause
JsonSerdeErrorserde_json::ErrorSerialization of a request body failed.
StrParseErrorstd::str::Utf8ErrorLog output or stream data contained invalid UTF-8.
IOErrorstd::io::ErrorI/O error on the socket or file system.
StrFmtErrorstd::fmt::ErrorString formatting failure.
HttpClientErrorhttp::ErrorHTTP request construction failed.
HyperResponseErrorhyper::ErrorLow-level Hyper HTTP error (connection reset, etc.).
URLEncodedErrorserde_urlencoded::ser::ErrorQuery parameter serialization failed.
URLParseErrorurl::ParseErrorA URL string could not be parsed.
InvalidURIErrorhttp::uri::InvalidUriA URI string was malformed.
InvalidURIPartsErrorhttp::uri::InvalidUriPartsURI parts could not be assembled.
HyperLegacyErrorhyper_util::client::legacy::ErrorError from the legacy hyper client connector. Only present with the http, ssh, or pipe Cargo features.
HttpHeaderToStrErrorhttp::header::ToStrErrorAn HTTP header value contained non-ASCII bytes.
Base64DecodeErrorbase64::DecodeErrorBase64 decoding of a header or payload failed.

Other variants

VariantDescription
UnsupportedURISchemeError { uri: String }The connection URL used a scheme Bollard does not support.
SocketNotFoundError(String)The Docker socket file was not found at the expected path.
DockerContextNotFoundError { name: String }A Docker context referenced by DOCKER_CONTEXT or ~/.docker/config.json does not exist on disk.
HttpHeaderNotFoundError(String)An expected HTTP response header was absent.
WebSocketError { err }A WebSocket connection failed. Only present with the websocket Cargo feature.

Pattern matching example

use bollard::Docker;
use bollard::errors::Error;

#[tokio::main]
async fn main() {
    let docker = Docker::connect_with_socket_defaults().unwrap();

    match docker.inspect_container("my-container", None).await {
        Ok(container) => {
            println!("Container state: {:?}", container.state);
        }
        Err(Error::DockerResponseServerError { status_code: 404, .. }) => {
            eprintln!("Container not found");
        }
        Err(Error::DockerResponseServerError { status_code, message }) => {
            eprintln!("Daemon error {status_code}: {message}");
        }
        Err(Error::RequestTimeoutError) => {
            eprintln!("Request timed out — is the Docker daemon running?");
        }
        Err(Error::IOError { err }) => {
            eprintln!("I/O error: {err}");
        }
        // Required: the enum is #[non_exhaustive]
        Err(e) => {
            eprintln!("Unexpected error: {e}");
        }
    }
}

Streaming error handling

For streaming operations, errors may arrive either as the Err variant of a stream item (DockerStreamError) or as an outer Result error. Handle both cases:
use bollard::Docker;
use bollard::errors::Error;
use bollard::image::CreateImageOptions;
use futures_util::stream::TryStreamExt;

#[tokio::main]
async fn main() -> Result<(), Error> {
    let docker = Docker::connect_with_socket_defaults()?;

    let options = CreateImageOptions {
        from_image: "alpine",
        tag: "latest",
        ..Default::default()
    };

    let mut stream = docker.create_image(Some(options), None, None);

    while let Some(info) = stream.try_next().await? {
        // DockerStreamError is returned as Err by try_next
        // Non-error progress events are returned as Ok
        if let Some(err) = info.error {
            eprintln!("Stream error: {err}");
            break;
        }
        println!("{:?}", info.status);
    }

    Ok(())
}
Because Error is #[non_exhaustive], omitting the _ => catch-all arm will cause a compile error when new variants are added in future Bollard releases. Always include it.

Build docs developers (and LLMs) love