Documentation ¶
Index ¶
- func New(ctx context.Context, opts ...NetworkCustomizer) (*testcontainers.DockerNetwork, error)
- func WithNetwork(aliases []string, nw *testcontainers.DockerNetwork) testcontainers.CustomizeRequestOption
- func WithNewNetwork(ctx context.Context, aliases []string, opts ...NetworkCustomizer) testcontainers.CustomizeRequestOption
- type CustomizeNetworkOption
- func WithAttachable() CustomizeNetworkOption
- func WithCheckDuplicate() CustomizeNetworkOptiondeprecated
- func WithDriver(driver string) CustomizeNetworkOption
- func WithEnableIPv6() CustomizeNetworkOption
- func WithIPAM(ipam *network.IPAM) CustomizeNetworkOption
- func WithInternal() CustomizeNetworkOption
- func WithLabels(labels map[string]string) CustomizeNetworkOption
- type NetworkCustomizer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(ctx context.Context, opts ...NetworkCustomizer) (*testcontainers.DockerNetwork, error)
New creates a new network with a random UUID name, calling the already existing GenericNetwork APIs. Those existing APIs are deprecated and will be removed in the future, so this function will implement the new network APIs when they will be available. By default, the network is created with the following options: - Driver: bridge - Labels: the Testcontainers for Go generic labels, to be managed by Ryuk. Please see the GenericLabels() function And those options can be modified by the user, using the CreateModifier function field.
Example ¶
package main import ( "context" "fmt" "log" "github.com/testcontainers/testcontainers-go/network" ) func main() { // createNetwork { ctx := context.Background() net, err := network.New(ctx) if err != nil { fmt.Println(err) return } defer func() { if err := net.Remove(ctx); err != nil { log.Printf("failed to remove network: %s", err) } }() // } fmt.Println(net.ID != "") fmt.Println(net.Driver) }
Output: true bridge
Example (WithOptions) ¶
package main import ( "context" "fmt" "log" dockernetwork "github.com/docker/docker/api/types/network" "github.com/testcontainers/testcontainers-go/network" ) func main() { // newNetworkWithOptions { ctx := context.Background() // dockernetwork is the alias used for github.com/docker/docker/api/types/network ipamConfig := dockernetwork.IPAM{ Driver: "default", Config: []dockernetwork.IPAMConfig{ { Subnet: "10.1.1.0/24", Gateway: "10.1.1.254", }, }, Options: map[string]string{ "driver": "host-local", }, } net, err := network.New(ctx, network.WithIPAM(&ipamConfig), network.WithAttachable(), network.WithDriver("bridge"), ) if err != nil { fmt.Println(err) return } defer func() { if err := net.Remove(ctx); err != nil { log.Printf("failed to remove network: %s", err) } }() // } fmt.Println(net.ID != "") fmt.Println(net.Driver) }
Output: true bridge
func WithNetwork ¶
func WithNetwork(aliases []string, nw *testcontainers.DockerNetwork) testcontainers.CustomizeRequestOption
WithNetwork reuses an already existing network, attaching the container to it. Finally it sets the network alias on that network to the given alias.
func WithNewNetwork ¶
func WithNewNetwork(ctx context.Context, aliases []string, opts ...NetworkCustomizer) testcontainers.CustomizeRequestOption
WithNewNetwork creates a new network with random name and customizers, and attaches the container to it. Finally it sets the network alias on that network to the given alias.
Types ¶
type CustomizeNetworkOption ¶
type CustomizeNetworkOption func(req *network.CreateOptions) error
CustomizeNetworkOption is a type that can be used to configure the network create request.
func WithAttachable ¶
func WithAttachable() CustomizeNetworkOption
WithAttachable allows to set the network as attachable.
func WithCheckDuplicate
deprecated
func WithCheckDuplicate() CustomizeNetworkOption
WithCheckDuplicate allows to check if a network with the same name already exists.
Deprecated: CheckDuplicate is deprecated since API v1.44, but it defaults to true when sent by the client package to older daemons.
func WithDriver ¶
func WithDriver(driver string) CustomizeNetworkOption
WithDriver allows to override the default network driver, which is "bridge".
func WithEnableIPv6 ¶
func WithEnableIPv6() CustomizeNetworkOption
WithEnableIPv6 allows to set the network as IPv6 enabled. Please use this option if and only if IPv6 is enabled on the Docker daemon.
func WithIPAM ¶
func WithIPAM(ipam *network.IPAM) CustomizeNetworkOption
WithIPAM allows to change the default IPAM configuration.
func WithInternal ¶
func WithInternal() CustomizeNetworkOption
WithInternal allows to set the network as internal.
func WithLabels ¶
func WithLabels(labels map[string]string) CustomizeNetworkOption
WithLabels allows to set the network labels, adding the new ones to the default Testcontainers for Go labels.
func (CustomizeNetworkOption) Customize ¶
func (opt CustomizeNetworkOption) Customize(req *network.CreateOptions) error
Customize implements the NetworkCustomizer interface, applying the option to the network create request.
type NetworkCustomizer ¶
type NetworkCustomizer interface {
Customize(req *network.CreateOptions) error
}
NetworkCustomizer is an interface that can be used to configure the network create request.