Skip to content

[Feature]: Network Driver Options #3301

Description

@Wielewout

Problem

When creating a network it's not possible to add driver options.

In our use case we want to inject a specific interface in the config of the container.
Given we attach the container to 3 networks we can't rely on it always being eth0 as the order changes each time for the corresponding networks.
There is also no stable order given a random docker network name is used, docker uses a map for the networks where the hashing will always result in different ordering with different docker instances, etc.

There is also not the option to exec into the container to discover the interface (as we can get to know the IP address via the container networks in an inspect and then search that way) as then we already are too late (the config is needed at startup).

So to work around all of this we want to set the driver option com.docker.network.container_iface_prefix so the interface name is determined beforehand.

Solution

A new NetworkCustomizer WithDriverOptions(driverOpts map[string]string) which sets a new field DriverOptions in NetworkRequest.

In the docker cli it's internally called driverOpts, but on the docker client type NetworkCreateOptions it's just called Options (i.e. without driver). So not sure what name you want to go for there.

Benefit

It allows for more control over network creation.

Alternatives

I don't immediately see any alternative implementation.

As a work-around I can create the docker network outside of testcontainers with the labels and create the reaper manually, but this is deprecated.

Would you like to help contributing this feature?

Yes

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew functionality or new behaviors on the existing one

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions