testcontainers / testcontainers/testcontainers-java

BrowserWebDriverContainer#withNetworkMode does not seem to work

Open
#915 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

resolution/acknowledged type/question
Dominant language
Java
Stars
8.7k
Forks
1.9k
Avg merge
2d 17h
Merged PRs (30d)
9

Description

Hi,
I am starting a Docker-Compose with (in Kotlin):

 @ClassRule
 @JvmField
 val env: DockerComposeContainer =
                    DockerComposeContainer(composeId, File("../docker-compose.yml"))
                                                    .withLocalCompose(true)

this works just fine. However, I want to add a Chrome Docker image to control with TestContainer, which should be on the same network of Docker Compose. In docker-compose.yml I specify the name of the default network manually (to make sure the name is deterministic with no random strings added to it), ie:

networks:
  default:
    name: foo-network

I then try to start Chrome with:

    @Rule
    @JvmField
    val browser: BrowserWebDriverContainer = BrowserWebDriverContainer()
            .withDesiredCapabilities(DesiredCapabilities.chrome())
            .withNetworkMode("foo-network")

However, that does not work. When I use docker inspect on the Chrome image, the setting foo-network is completely ignored, and I get a new network with a random name, eg:

 "Networks": {
                "7af40cfa-f262-463c-accb-1707bdd8f2d9": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": [
                        "tc-qEF38kvs",
                        "a8bd32b1f2f3"
                    ],
                    "NetworkID": "96313abc29bedbb992f754ba6684a3c8847bcd7f8bf9af547ce6fb38b0152a91",
                    "EndpointID": "6851d5ba06dda964677f57263a03806c47aea7d3a021fb2e71b3f14fe895664f",
                    "Gateway": "192.168.48.1",
                    "IPAddress": "192.168.48.2",
                    "IPPrefixLen": 20,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:c0:a8:30:02",
                    "DriverOpts": null
                }
            }

Is there a better way to connect BrowserWebDriverContainer to an existing Docker Compose network? And in any case, if how I use withNetworkMode is wrong, it would be good if TestContainer threw an exception with some info.

TestContainer version: 1.9.1
Docker version: 18.06.1
OS: Mac 10.12.6

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 BrowserWebDriverContainer#withNetworkMode and DockerComposeContainer, reproducing the supplied docker-compose.yml network declaration and inspecting the created container's networks. Done means determining why foo-network is ignored and establishing the supported connection behavior, including an informative failure if the mode is invalid.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, docker-compose, java, kotlin
Domain
networking, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.