Network class final
A Docker network of the test run: containers put on it with
GenericContainer.withNetwork reach each other by the names given
with withNetworkAliases, on the ports they listen on (not the ports
published to the host).
static final network = Network.newNetwork();
@Container()
static final database = PostgresContainer('postgres:17-alpine')
.withNetwork(network)
.withNetworkAliases(['db']);
@Container()
static final api = GenericContainer('postgrest/postgrest:v12.2.3')
.withNetwork(network)
.withEnv('PGRST_DB_URI', 'postgres://test:test@db:5432/test')
.withExposedPorts([3000]);
The network is created when its first container starts and carries the run's label, so the reaper removes it with the run's containers (also when the process is killed). close removes it sooner, once its containers have stopped.
Testcontainers (Java): Network.newNetwork().
Constructors
- Network.newNetwork()
-
A network with a name of its own; nothing happens until a container
on it starts.
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isCreated → bool
-
Whether the network was created (and not closed since).
no setter
- name → String
-
The network's name, as containers are created on it.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
close(
) → Future< void> - Removes the network; its containers must have stopped. A network that was never created, could not be created, or is gone, is no error.
-
create(
DockerClient docker) → Future< String> -
The network's id, creating it on the daemon of
dockerat the first call. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited