Skip to content

Testcontainers#exposeHostPorts does not work together with reuse #3457

@jakobbraun

Description

@jakobbraun

When reusing a container together with Testcontainers#exposeHostPorts the second container startup fails with an exception.

Example (using testconatienrs 1.15.0):

package com.example;

import org.junit.jupiter.api.Test;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Testcontainers;

@Testcontainers
public class MyTest {

    @Test
    void test() {
        org.testcontainers.Testcontainers.exposeHostPorts(8000);
        final GenericContainer container = new GenericContainer<>("alpine").withReuse(true).withCommand("top");
        container.start();

        final GenericContainer container2 = new GenericContainer<>("alpine").withReuse(true).withCommand("top");
        container2.start();
    }
}

Result:

org.testcontainers.containers.ContainerLaunchException: Container startup failed
Caused by: org.rnorth.ducttape.RetryCountExceededException: Retry limit hit with exception
Caused by: org.testcontainers.containers.ContainerLaunchException: Could not create/start container
Caused by: com.github.dockerjava.api.exception.DockerException: Status 403: {"message":"endpoint with name objective_benz already exists in network bridge"}

Expected Result:

  • no exception is thrown
  • Host is reachable from inside the container under host.testcontainers.internal:8000

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