testcontainers-cpp 0.2.0
Native C++20 Testcontainers over the Docker Engine API
Loading...
Searching...
No Matches
testcontainers::DockerHost Class Reference

A resolved Docker daemon endpoint: where and how to reach the daemon. More...

#include <testcontainers/docker/DockerHost.hpp>

Public Member Functions

DockerScheme scheme () const noexcept
const std::string & path () const noexcept
 Socket path (unix) or pipe path (named pipe). Empty for tcp/https.
const std::string & hostname () const noexcept
 Host name (tcp/https). Empty for unix/named pipe.
std::uint16_t port () const noexcept
 TCP port (tcp/https). 0 for unix/named pipe.
std::string http_host () const
 Value to use for the HTTP Host header.
const std::string & to_string () const noexcept
 The original (normalized) URL, for logging/diagnostics.
const std::optional< TlsMaterials > & tls_materials () const noexcept
 TLS materials from the docker context that produced this endpoint (resolve() step 3); nullopt for every other origin, including parse().

Static Public Member Functions

static DockerHost resolve ()
 Resolve from the environment / platform defaults.
static DockerHost parse (const std::string &url)
 Parse an explicit Docker host URL (unix://, npipe://, tcp://, http://, https://).

Detailed Description

A resolved Docker daemon endpoint: where and how to reach the daemon.

Resolution order (first hit wins), mirroring testcontainers:

  1. DOCKER_HOST environment variable.
  2. docker.host in ~/.testcontainers.properties. In both steps a tcp:// / http:// / scheme-less host upgrades to https when TLS verification is on (DOCKER_TLS_VERIFY, or the docker.tls.verify properties key) — the docker CLI treats such a host as a TLS endpoint, and the default port moves 2375 -> 2376.
  3. The active Docker context's endpoint: the context name is DOCKER_CONTEXT, else currentContext in ~/.docker/config.json, else "default". A non-"default" name reads Endpoints.docker.Host from ~/.docker/contexts/meta/<sha256(name)>/meta.json. When the context also stores TLS materials (~/.docker/contexts/tls/<sha256(name)>/docker/*.pem), they are attached to the resolved host — see tls_materials() — and a tcp:// endpoint is likewise treated as https; Endpoints.docker.SkipTLSVerify turns server verification off.
  4. Platform default: Windows named pipe //./pipe/docker_engine; otherwise the rootless sockets $XDG_RUNTIME_DIR/docker.sock then $HOME/.docker/run/docker.sock (if they exist), else the unix socket /var/run/docker.sock.

Steps 2-4 never throw on a malformed/absent file — they fall through to the next step. A malformed DOCKER_HOST (step 1) still throws via parse().

Member Function Documentation

◆ resolve()

DockerHost testcontainers::DockerHost::resolve ( )
static

Resolve from the environment / platform defaults.

◆ parse()

DockerHost testcontainers::DockerHost::parse ( const std::string & url)
static

Parse an explicit Docker host URL (unix://, npipe://, tcp://, http://, https://).

Throws DockerError on an unsupported scheme. The scheme is taken at face value: parse() never applies the TLS-verify upgrade or context materials that resolve() does — spell https:// explicitly for a TLS endpoint.

◆ scheme()

DockerScheme testcontainers::DockerHost::scheme ( ) const
inlinenoexcept

◆ path()

const std::string & testcontainers::DockerHost::path ( ) const
inlinenoexcept

Socket path (unix) or pipe path (named pipe). Empty for tcp/https.

◆ hostname()

const std::string & testcontainers::DockerHost::hostname ( ) const
inlinenoexcept

Host name (tcp/https). Empty for unix/named pipe.

◆ port()

std::uint16_t testcontainers::DockerHost::port ( ) const
inlinenoexcept

TCP port (tcp/https). 0 for unix/named pipe.

◆ http_host()

std::string testcontainers::DockerHost::http_host ( ) const

Value to use for the HTTP Host header.

◆ to_string()

const std::string & testcontainers::DockerHost::to_string ( ) const
inlinenoexcept

The original (normalized) URL, for logging/diagnostics.

◆ tls_materials()

const std::optional< TlsMaterials > & testcontainers::DockerHost::tls_materials ( ) const
inlinenoexcept

TLS materials from the docker context that produced this endpoint (resolve() step 3); nullopt for every other origin, including parse().