Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Cannot reuse containers due to "endpoint with name XYZ already exists in network bridge" #7335

Closed
abialas opened this issue Jul 26, 2023 · 4 comments

Comments

@abialas
Copy link

abialas commented Jul 26, 2023

Module

Core

Testcontainers version

1.18.3

Using the latest Testcontainers version?

Yes

Host OS

MacOS

Host Arch

x86

Docker version

Client:
 Version:           24.0.2-rd
 API version:       1.42 (downgraded from 1.43)
 Go version:        go1.20.4
 Git commit:        e63f5fa
 Built:             Fri May 26 16:39:47 2023
 OS/Arch:           darwin/amd64
 Context:           default

Server:
 Engine:
  Version:          23.0.6
  API version:      1.42 (minimum version 1.12)
  Go version:       go1.20.4
  Git commit:       9dbdbd4b6d7681bd18c897a6ba0376073c2a72ff
  Built:            Fri May 12 13:54:36 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.7.0
  GitCommit:        1fbd70374134b891f97ce19c70b6e50c7b9f4e0d
 runc:
  Version:          1.1.7
  GitCommit:        860f061b76bb4fc671f0f9e900f7d80ff93d4eb7
 docker-init:
  Version:          0.19.0
  GitCommit:

What happened?

In my integration test I am using KafkaContainer with reuse enabled. I have reuse enabled also in my user directory (~/.testcontainers.properties). When I run test for the first time they work fine - container starts and tests pass. However, when I try to run test next time I get te following error:

com.github.dockerjava.api.exception.DockerException: Status 403: {"message":"endpoint with name wonderful_jang already exists in network bridge"}

In order to fix that I have to remove running containers and run test once again.

Relevant log output

Caused by: org.testcontainers.containers.ContainerLaunchException: Could not create/start container
      at app//org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:542)
      at app//org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:344)
      at app//org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
      ... 76 more
  Caused by: com.github.dockerjava.api.exception.DockerException: Status 403: {"message":"endpoint with name wonderful_jang already exists in network bridge"}
      at app//org.testcontainers.shaded.com.github.dockerjava.core.DefaultInvocationBuilder.execute(DefaultInvocationBuilder.java:249)
      at app//org.testcontainers.shaded.com.github.dockerjava.core.DefaultInvocationBuilder.post(DefaultInvocationBuilder.java:102)
      at app//org.testcontainers.shaded.com.github.dockerjava.core.exec.ConnectToNetworkCmdExec.execute(ConnectToNetworkCmdExec.java:27)
      at app//org.testcontainers.shaded.com.github.dockerjava.core.exec.ConnectToNetworkCmdExec.execute(ConnectToNetworkCmdExec.java:11)
      at app//org.testcontainers.shaded.com.github.dockerjava.core.exec.AbstrSyncDockerCmdExec.exec(AbstrSyncDockerCmdExec.java:21)
      at app//org.testcontainers.shaded.com.github.dockerjava.core.command.AbstrDockerCmd.exec(AbstrDockerCmd.java:35)
      at app//org.testcontainers.containers.GenericContainer.lambda$connectToPortForwardingNetwork$7(GenericContainer.java:613)
      at java.base@17.0.1/java.util.Optional.ifPresent(Optional.java:178)
      at app//org.testcontainers.containers.GenericContainer.connectToPortForwardingNetwork(GenericContainer.java:611)
      at app//org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:435)

Additional Information

No response

@eddumelendez
Copy link
Member

Can you share your setup, please?

@abialas
Copy link
Author

abialas commented Jul 31, 2023

Not sure what else do you need. This is how I start container (using singleton pattern):

public static final KafkaContainer KAFKA;

  static {
    KAFKA =
        new KafkaContainer(
            DockerImageName.parse("<our-nexus>/confluentinc/cp-kafka:5.4.3")
                .asCompatibleSubstituteFor("confluentinc/cp-kafka:5.4.3"));
    KAFKA.start();
  }

@jbaris
Copy link

jbaris commented Sep 11, 2023

Same issue here. Do you have any progress?

@tbieniek
Copy link

tbieniek commented Oct 6, 2023

I have got the same problem

public class PostgreSqlContainerWrapper extends PostgreSQLContainer<PostgreSqlContainerWrapper> {

    private static final String IMAGE_VERSION = "postgres:11.1";
    private static PostgreSqlContainerWrapper container;

    private PostgreSqlContainerWrapper() {
        super(IMAGE_VERSION);
    }

    static PostgreSqlContainerWrapper getInstance() {
        if (container == null) {
            container = new PostgreSqlContainerWrapper()
                    .withExposedPorts(POSTGRESQL_PORT)
                    .withPassword("test")
                    .withUsername("test")
                    .withDatabaseName("test")
                    .withAccessToHost(true)
                    .withReuse(true);
            container.start();
        }
        return container;
    }

    @Override
    public void start() {
        super.start();
    }

    @Override
    public void stop() {
        //do nothing, JVM handles shut down
    }

    @Override
    public void close() {
        container.close();
    }
}

I have also testcontainer.properties file in $HOME

testcontainers.reuse.enable=true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants