testcontainers / testcontainers/testcontainers-java
[Enhancement]: Throw exception if user tries to set network mode "host"
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 8.7k
- Forks
- 1.9k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 9
Description
Module
Core
Proposal
Discussion spawned off of https://github.com/testcontainers/testcontainers-java/issues/5151
As per the docker docs:
The host networking driver only works on Linux hosts, and is not supported on Docker Desktop for Mac, Docker Desktop for Windows, or Docker EE for Windows Server.
I think we should throw an exception if a user tries to set network mode "host" if they aren't on linux. E.g.
@Override
public SELF withNetworkMode(String networkMode) {
if (networkMode.equals("host") && !SystemUtils.IS_OS_LINUX) {
throw new IllegalArgumentException(
"You are using the 'host' network mode, which is not supported on non-Linux platforms."
);
}
this.networkMode = networkMode;
return self();
}
Our users will experience a lot of weirdness otherwise.
- The container will not be be reachable via any port.
- If a container has any exposed ports, the container won't be able to start up (as we check for the tcp port to open up but it never does in
HostPortWaitStrategy). HttpWaitStrategywon't work
I think we can prevent headache if we did this.
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 at the withNetworkMode(String networkMode) entry point in the Core module and review how network mode is stored and used. Check the existing behavior around HostPortWaitStrategy and HttpWaitStrategy, then verify that unsupported host networking is rejected on non-Linux platforms while Linux behavior remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, java
- Domain
- networking
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100