Skip to content

[Enhancement]: PortForwardingContainer breaks reuse hash #1673

@flynny75

Description

@flynny75

Problem

I am using a message broker container with reuse.

I am using other transient containers that need to be able to reach the host.

I am requesting TestContainers expose the ports after creating the reuse container, but before the transient containers. When ran in isolation this works well.

I am using TestContainers to run multiple integration tests at the same time, sharing the reuse container between multiple tests.

The issue I am facing is the second test runs, attempts to start the reuse container (which is already running, and was started before the PortForwardingContainer), but the builder now has ExtraHosts configured because the PortForwardingContainer is now running. Thus the hash calculation is different and the reuse container is now a clash.

This is because the default implementation of container builder init is to apply the port forwarding if the (static) PortForwardingContainer is running.

Solution

Provide the ability for a container builder to clear the ExtraHosts

OR expose WithPortForwarding such that a container builder can 'opt in' to using the PortForwardingContainer

Benefit

Container reuse would cooperate with transient containers that require port forwarding

Alternatives

N/A

Would you like to help contributing this enhancement?

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestmoduleAn official Testcontainers module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions