testcontainers / testcontainers/testcontainers-go
[Feature]: Network Driver Options
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 5k
- Forks
- 637
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 26
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the NetworkCustomizer and NetworkRequest types involved in network creation, then compare their API with Docker's NetworkCreateOptions and its Options field. Implement the requested driver-options path and verify that network creation passes the configured option through to Docker; add or update focused tests for the new behavior if the surrounding code provides them.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, go
- Domain
- networking
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100