testcontainers / testcontainers/testcontainers-java

[Enhancement]: Throw exception if user tries to set network mode "host"

Open
#5,853 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type/enhancement
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).
  • HttpWaitStrategy won't work

I think we can prevent headache if we did this.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.