|
testcontainers-cpp 0.2.0
Native C++20 Testcontainers over the Docker Engine API
|
A RAII handle to a user-defined Docker network. More...
#include <testcontainers/Network.hpp>
Classes | |
| class | Builder |
| A copyable builder for a richer user-defined network: driver, internal / attachable / IPv6 flags, IPAM address pools, driver options, and labels. More... | |
Public Member Functions | |
| Network (const Network &)=delete | |
| Network & | operator= (const Network &)=delete |
| Network (Network &&other) noexcept | |
| Network & | operator= (Network &&other) noexcept |
| ~Network () | |
| Removes the network unless it was already explicitly removed or moved-from. | |
| const std::string & | name () const noexcept |
| The network's name (used by containers to join it / resolve peers). | |
| const std::string & | id () const noexcept |
| The network's id. | |
| bool | is_persistent () const noexcept |
| True when this handle will NOT remove the network on destruction (after keep()). | |
| NetworkInspect | inspect () const |
| A structured snapshot of this network (GET /networks/{id}): driver, flags, IPAM pools, options, labels, and the currently attached containers. | |
| std::string | inspect_raw () const |
| The RAW inspect JSON body (GET /networks/{id}), so callers can read any field NetworkInspect does not model. | |
| void | keep (bool keep=true) noexcept |
| Keep the network alive past this handle: from here on neither destruction nor remove() removes it (is_persistent() reports true afterwards) — removing the network becomes the caller's responsibility (e.g. | |
| void | remove () |
| Explicitly remove the network now. | |
| void | connect (const std::string &container_id, const std::vector< std::string > &aliases={}) const |
| Connect an already-running container to this network, optionally giving it DNS aliases on this network. | |
Static Public Member Functions | |
| static Builder | builder () |
| Start a builder for a richer network (driver, IPAM, options, labels). | |
| static Network | create (std::string name) |
| Create a network with the given name. | |
| static Network | create () |
| Create a network with a generated unique name (tc-<random hex>). | |
| static NetworkInspect | inspect (const std::string &id_or_name) |
| A structured snapshot of an arbitrary network by name or id, without a Network handle (the daemon accepts both forms). | |
A RAII handle to a user-defined Docker network.
Move-only: it owns a real external resource and removes the network on destruction (best-effort, exceptions swallowed). Copying is deleted so the removal happens exactly once; keep() releases removal ownership (the network then outlives the handle). Containers placed on the same network (via GenericImage::with_network) can resolve each other by container name.
|
delete |
|
inlinenoexcept |
|
inline |
Removes the network unless it was already explicitly removed or moved-from.
Never throws.
|
inlinestatic |
Start a builder for a richer network (driver, IPAM, options, labels).
|
static |
Create a network with the given name.
|
static |
Create a network with a generated unique name (tc-<random hex>).
|
inlinenoexcept |
The network's name (used by containers to join it / resolve peers).
|
inlinenoexcept |
The network's id.
|
inlinenoexcept |
True when this handle will NOT remove the network on destruction (after keep()).
| NetworkInspect testcontainers::Network::inspect | ( | ) | const |
A structured snapshot of this network (GET /networks/{id}): driver, flags, IPAM pools, options, labels, and the currently attached containers.
Throws DockerError if the network is gone.
| std::string testcontainers::Network::inspect_raw | ( | ) | const |
The RAW inspect JSON body (GET /networks/{id}), so callers can read any field NetworkInspect does not model.
Throws DockerError if the network is gone.
|
static |
A structured snapshot of an arbitrary network by name or id, without a Network handle (the daemon accepts both forms).
Connects via DockerClient::from_environment(). Throws DockerError if no such network exists (NotFoundError) or the daemon cannot be reached.
|
inlinenoexcept |
Keep the network alive past this handle: from here on neither destruction nor remove() removes it (is_persistent() reports true afterwards) — removing the network becomes the caller's responsibility (e.g.
DockerClient::remove_network or docker network rm). keep(false) re-arms removal — handy for forwarding a "keep my resources" debug flag in one call instead of an if.
Ryuk still applies on Linux engines: a created network carries the session label, so the reaper removes it shortly after the test process exits — keep() only protects it from THIS process's teardown. For a network that must outlive the process, disable the reaper (TESTCONTAINERS_RYUK_DISABLED). (No reaper runs against a Windows-containers engine — a kept network there stays until you remove it.)
| void testcontainers::Network::remove | ( | ) |
Explicitly remove the network now.
Idempotent; after this the destructor does nothing. On a kept handle (after keep()) this releases ownership without removing the network.
| void testcontainers::Network::connect | ( | const std::string & | container_id, |
| const std::vector< std::string > & | aliases = {} ) const |
Connect an already-running container to this network, optionally giving it DNS aliases on this network.
Lets a container join after it was started (e.g. without GenericImage::with_network).