Skip to content

.withReuse(true) doesn't work for containers within a dedicated network #2838

Description

@TheOneAndOnlyAndreKempe

Hej guys,

we're trying to get two containers within a dedicated network to work with the new reuse-capabilities. However to no avail. A new set of containers is started whenever the tests are being run. I reproduced the scenario using the network-example

Networknetwork = Network.newNetwork( );
GenericContainer<?> foo = newGenericContainer<>( )
.withReuse( true )
.withNetwork( network )
.withNetworkAliases( "foo" )
.withCommand( "/bin/sh", "-c", "while true ; do printf 'HTTP/1.1 200 OK\\n\\nyay' | nc -l -p 8080; done" );
GenericContainer<?> bar = newGenericContainer<>( )
.withReuse( true )
.withNetwork( network )
.withCommand( "top" );
foo.start( );
bar.start( );
Stringresponse = bar.execInContainer( "wget", "-O", "-", "http://foo:8080" ).getStdout( );
assertEquals( "yay", response, "received response" );`

Output of the first run:

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fb0070ec29b9 alpine:3.5 "top" 21 seconds ago Up 20 seconds musing_nobel
f4b4b7e62a56 alpine:3.5 "/bin/sh -c 'while t…" 21 seconds ago Up 21 seconds friendly_jepsen

Output of the second run:

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
afbc55ed865a alpine:3.5 "top" 33 seconds ago Up 32 seconds blissful_kilby
21d2b7b15c35 alpine:3.5 "/bin/sh -c 'while t…" 34 seconds ago Up 33 seconds exciting_kapitsa
fb0070ec29b9 alpine:3.5 "top" About a minute ago Up About a minute musing_nobel
f4b4b7e62a56 alpine:3.5 "/bin/sh -c 'while t…" About a minute ago Up About a minute friendly_jepsen

When I remove the usage of the network, the containers are reused as expected (yepp, besides .withResuse(true) I also changed the properties-file, but of course the test fails now).

I tried to provide a fixed network-name using the network-command-modifier. However, this approach results in complaints about duplicated network-names

Networknetwork = Network.builder( )
.createNetworkCmdModifier( cmd -> cmd.withName( "test-network" ) )
.build();

Am I missing a way to make this work, or is there anything that makes reused containers in a dedicated network a bad idea? All ideas and thoughts are greatly appreciated!

Thanks for your help, Best regards + cheers,
André

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