Bollard provides several ways to establish a connection to Docker or Podman depending on your environment and security requirements. All connection methods require a Tokio Runtime.
Local Connection (Recommended)
Automatically detects the best available socket on the local machine.
use bollard::Docker;
Docker::connect_with_local_defaults();
Podman Connection
Explicitly connects to Podman with automatic rootless/system socket discovery (Unix only). It probes $DOCKER_HOST, then rootless Podman sockets, then the system Podman socket, and finally falls back to the Docker socket.
use bollard::Docker;
Docker::connect_with_podman_defaults();
Unix Socket / Windows Named Pipe
Connects to the standard /var/run/docker.sock (Unix) or //./pipe/docker_engine (Windows).
use bollard::Docker;
#[cfg(unix)]
Docker::connect_with_socket_defaults();
HTTP Connection
Connects to the location in $DOCKER_HOST, or localhost:2375 if the variable is missing.
use bollard::Docker;
Docker::connect_with_http_defaults();
SSL via Rustls
Connects via HTTPS using $DOCKER_HOST. It searches $DOCKER_CERT_PATH for key.pem, cert.pem, and ca.pem.
use bollard::Docker;
#[cfg(feature = "ssl")]
Docker::connect_with_ssl_defaults();
SSH Connection
Connects via SSH using $DOCKER_HOST or ssh://localhost.
use bollard::Docker;
#[cfg(feature = "ssh")]
Docker::connect_with_ssh_defaults();