Skip to content

Commit 3bb9b7f

Browse files
committed
feat: add network driver options
1 parent d9a7436 commit 3bb9b7f

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

docker.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,7 @@ func (p *DockerProvider) CreateNetwork(ctx context.Context, req NetworkRequest)
15751575

15761576
nc := network.CreateOptions{
15771577
Driver: req.Driver,
1578+
Options: req.DriverOptions,
15781579
Internal: req.Internal,
15791580
EnableIPv6: req.EnableIPv6,
15801581
Attachable: req.Attachable,

docs/features/networking.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Then, you can create a network using the `network.New` function. This function r
1717
- `WithAttachable()`
1818
- `WithCheckDuplicate()`
1919
- `WithDriver(driver string)`
20+
- `WithDriverOptions(options map[string]string)`
2021
- `WithEnableIPv6()`
2122
- `WithInternal()`
2223
- `WithLabels(labels map[string]string)`

network.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func (n DefaultNetwork) ApplyDockerTo(opts *DockerProviderOptions) {
3737
// NetworkRequest represents the parameters used to get a network
3838
type NetworkRequest struct {
3939
Driver string
40+
DriverOptions map[string]string
4041
CheckDuplicate bool // Deprecated: CheckDuplicate is deprecated since API v1.44, but it defaults to true when sent by the client package to older daemons.
4142
Internal bool
4243
EnableIPv6 *bool

network/network.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ func New(ctx context.Context, opts ...NetworkCustomizer) (*testcontainers.Docker
3333

3434
//nolint:staticcheck
3535
netReq := testcontainers.NetworkRequest{
36-
Driver: nc.Driver,
37-
Internal: nc.Internal,
38-
EnableIPv6: nc.EnableIPv6,
39-
Name: uuid.NewString(),
40-
Labels: nc.Labels,
41-
Attachable: nc.Attachable,
42-
IPAM: nc.IPAM,
36+
Driver: nc.Driver,
37+
DriverOptions: nc.Options,
38+
Internal: nc.Internal,
39+
EnableIPv6: nc.EnableIPv6,
40+
Name: uuid.NewString(),
41+
Labels: nc.Labels,
42+
Attachable: nc.Attachable,
43+
IPAM: nc.IPAM,
4344
}
4445

4546
//nolint:staticcheck
@@ -96,6 +97,15 @@ func WithDriver(driver string) CustomizeNetworkOption {
9697
}
9798
}
9899

100+
// WithDriverOptions allows to set driver options.
101+
func WithDriverOptions(options map[string]string) CustomizeNetworkOption {
102+
return func(original *network.CreateOptions) error {
103+
original.Options = options
104+
105+
return nil
106+
}
107+
}
108+
99109
// WithEnableIPv6 allows to set the network as IPv6 enabled.
100110
// Please use this option if and only if IPv6 is enabled on the Docker daemon.
101111
func WithEnableIPv6() CustomizeNetworkOption {

0 commit comments

Comments
 (0)