diff --git a/docker.go b/docker.go index fbb7298f74..422741ca12 100644 --- a/docker.go +++ b/docker.go @@ -1575,6 +1575,7 @@ func (p *DockerProvider) CreateNetwork(ctx context.Context, req NetworkRequest) nc := network.CreateOptions{ Driver: req.Driver, + Options: req.DriverOptions, Internal: req.Internal, EnableIPv6: req.EnableIPv6, Attachable: req.Attachable, diff --git a/docs/features/networking.md b/docs/features/networking.md index e665cca11d..eae7248efc 100644 --- a/docs/features/networking.md +++ b/docs/features/networking.md @@ -17,6 +17,7 @@ Then, you can create a network using the `network.New` function. This function r - `WithAttachable()` - `WithCheckDuplicate()` - `WithDriver(driver string)` +- `WithDriverOptions(options map[string]string)` - `WithEnableIPv6()` - `WithInternal()` - `WithLabels(labels map[string]string)` diff --git a/network.go b/network.go index e0cc83f510..68a5253366 100644 --- a/network.go +++ b/network.go @@ -37,6 +37,7 @@ func (n DefaultNetwork) ApplyDockerTo(opts *DockerProviderOptions) { // NetworkRequest represents the parameters used to get a network type NetworkRequest struct { Driver string + DriverOptions map[string]string CheckDuplicate bool // Deprecated: CheckDuplicate is deprecated since API v1.44, but it defaults to true when sent by the client package to older daemons. Internal bool EnableIPv6 *bool diff --git a/network/network.go b/network/network.go index f383ad821d..1085707638 100644 --- a/network/network.go +++ b/network/network.go @@ -33,13 +33,14 @@ func New(ctx context.Context, opts ...NetworkCustomizer) (*testcontainers.Docker //nolint:staticcheck netReq := testcontainers.NetworkRequest{ - Driver: nc.Driver, - Internal: nc.Internal, - EnableIPv6: nc.EnableIPv6, - Name: uuid.NewString(), - Labels: nc.Labels, - Attachable: nc.Attachable, - IPAM: nc.IPAM, + Driver: nc.Driver, + DriverOptions: nc.Options, + Internal: nc.Internal, + EnableIPv6: nc.EnableIPv6, + Name: uuid.NewString(), + Labels: nc.Labels, + Attachable: nc.Attachable, + IPAM: nc.IPAM, } //nolint:staticcheck @@ -96,6 +97,15 @@ func WithDriver(driver string) CustomizeNetworkOption { } } +// WithDriverOptions allows to set driver options. +func WithDriverOptions(options map[string]string) CustomizeNetworkOption { + return func(original *network.CreateOptions) error { + original.Options = options + + return nil + } +} + // 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 WithEnableIPv6() CustomizeNetworkOption {