Skip to content

.withReuse(true) is broken out of the box because of randomly assigned network alias #2801

Closed

Description

@aaronjwhiteside

On line:

https://github.com/testcontainers/testcontainers-java/blob/master/core/src/main/java/org/testcontainers/containers/GenericContainer.java#L136-L139

A random network alias is assigned during field initialization time, this ALWAYS prevents the computed hash from matching, unless one calls container.getNetworkAliases().clear() before adding their own network alias with .withNetworkAliases("some static value").

I propose that the default behaviour to allocate a random network alias be changed to happen lazily and when no other explictly specified network alias is set.

And also perhaps print a warning/error when no explict network alias is defined and .withReuse(true) is used.

Activity

  1. bsideup commented on May 28, 2020

    @bsideup
    Member

    @aaronjwhiteside yes, Reusable Containers are not compatible with networks as stated in the PR:
    #1781

    Also, I would not call it "broken", but rather "not supported" (yet). We have some ideas how to support Networks (even if you fix the aliasing, the Network id is still random), but it requires a bit of time.

  2. aaronjwhiteside commented on May 28, 2020

    @aaronjwhiteside
    ContributorAuthor

    @bsideup I have it working by clearing the assigned network aliases and using a custom implementation of Network.

    I'd be interested to hear what ideas you have, even if I may better use them in our setup. I'd be happy to contribute too.

    On the flip side I kinda feel that if it's "not supported" yet that things should fail-fast and hard with informative error messages.

  3. bharath-tw commented on Aug 12, 2022

    @bharath-tw

    A simpler way would be to directly set the networkAliases via setNetworkAliases(List.of("kafka"))

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions