dasniko / testcontainers-keycloak

A Testcontainer implementation for Keycloak IAM & SSO.
Apache License 2.0
328 stars 51 forks source link

"endpoint with name XX already exists in network bridge" while running withReuse #33

Closed lmsurpre closed 2 years ago

lmsurpre commented 3 years ago

I can't tell if this is something specific to testcontainers-keycloak or a more generic testcontainers issue, but figured I'd start here.

Previously, I was able to call withReuse(true) on my KeycloakContainer (before starting it) and it would let me re-use the same container from one run to the next which was very useful to reduce the cycle time on test development.

Now, when I try the same thing, everything after the first run is failing with an error like this:

13:07:40.153 [main] ERROR 🐳 [quay.io/keycloak/keycloak:13.0.1] - Could not start container
com.github.dockerjava.api.exception.DockerException: Status 403: {"message":"endpoint with name quizzical_leakey already exists in network bridge"}

I backed out to testcontainers-keycloak version 1.6.1 (where I think this was working before), but it turns out I'm seeing the same behavior there. I'm wondering if its related to some underlying Docker for Mac changes or something...

Please let me know if you have any ideas for me to try.

Full stacktrack:

13:07:34.944 [main] INFO  org.testcontainers.dockerclient.DockerClientProviderStrategy - Loaded org.testcontainers.dockerclient.UnixSocketClientProviderStrategy from ~/.testcontainers.properties, will try it first
13:07:35.717 [main] INFO  org.testcontainers.dockerclient.DockerClientProviderStrategy - Found Docker environment with local Unix socket (unix:///var/run/docker.sock)
13:07:35.719 [main] INFO  org.testcontainers.DockerClientFactory - Docker host IP address is localhost
13:07:35.772 [main] INFO  org.testcontainers.DockerClientFactory - Connected to docker: 
  Server Version: 20.10.6
  API Version: 1.41
  Operating System: Docker Desktop
  Total Memory: 7962 MB
13:07:35.776 [main] INFO  org.testcontainers.utility.ImageNameSubstitutor - Image name substitution will be performed by: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor')
13:07:35.880 [main] INFO  org.testcontainers.utility.RegistryAuthLocator - Failure when attempting to lookup auth config. Please ignore if you don't have images in an authenticated registry. Details: (dockerImageName: testcontainers/ryuk:0.3.1, configFile: /Users/lmsurpre/.docker/config.json. Falling back to docker-java default behaviour. Exception message: Could not execute [docker-credential-desktop, get]. Error=2, No such file or directory
13:07:37.512 [main] INFO  org.testcontainers.DockerClientFactory - Ryuk started - will monitor and terminate Testcontainers containers on JVM exit
13:07:37.512 [main] INFO  org.testcontainers.DockerClientFactory - Checking the system...
13:07:37.513 [main] INFO  org.testcontainers.DockerClientFactory - ✔︎ Docker server version should be at least 1.6.0
13:07:37.632 [main] INFO  org.testcontainers.DockerClientFactory - ✔︎ Docker environment should have more than 2GB free disk space
13:07:37.679 [main] INFO  🐳 [testcontainers/sshd:1.0.0] - Creating container for image: testcontainers/sshd:1.0.0
13:07:37.733 [main] INFO  🐳 [testcontainers/sshd:1.0.0] - Starting container with ID: 301ba689ac86b1b8281ca9816afbe17feadf5bf2b3ad8b93b6a16084902a23f9
13:07:39.102 [main] INFO  🐳 [testcontainers/sshd:1.0.0] - Container testcontainers/sshd:1.0.0 is starting: 301ba689ac86b1b8281ca9816afbe17feadf5bf2b3ad8b93b6a16084902a23f9
13:07:39.246 [main] INFO  🐳 [testcontainers/sshd:1.0.0] - Container testcontainers/sshd:1.0.0 started in PT1.61S
13:07:39.454 [main] INFO  🐳 [quay.io/keycloak/keycloak:13.0.1] - Creating container for image: quay.io/keycloak/keycloak:13.0.1
13:07:39.463 [main] INFO  org.testcontainers.utility.RegistryAuthLocator - Failure when attempting to lookup auth config. Please ignore if you don't have images in an authenticated registry. Details: (dockerImageName: quay.io/keycloak/keycloak:13.0.1, configFile: /Users/lmsurpre/.docker/config.json. Falling back to docker-java default behaviour. Exception message: Could not execute [docker-credential-desktop, get]. Error=2, No such file or directory
13:07:40.138 [main] INFO  🐳 [quay.io/keycloak/keycloak:13.0.1] - Reusing container with ID: de1c46323de3f5b4ddbdbf995ddfc82760a0260c0bca2bdbe7d86a981f730579 and hash: 0949650de30d970c3118393ac7a77c67b722284b
13:07:40.153 [main] ERROR 🐳 [quay.io/keycloak/keycloak:13.0.1] - Could not start container
com.github.dockerjava.api.exception.DockerException: Status 403: {"message":"endpoint with name quizzical_leakey already exists in network bridge"}

    at org.testcontainers.shaded.com.github.dockerjava.core.DefaultInvocationBuilder.execute(DefaultInvocationBuilder.java:249)
    at org.testcontainers.shaded.com.github.dockerjava.core.DefaultInvocationBuilder.post(DefaultInvocationBuilder.java:102)
    at org.testcontainers.shaded.com.github.dockerjava.core.exec.ConnectToNetworkCmdExec.execute(ConnectToNetworkCmdExec.java:27)
    at org.testcontainers.shaded.com.github.dockerjava.core.exec.ConnectToNetworkCmdExec.execute(ConnectToNetworkCmdExec.java:11)
    at org.testcontainers.shaded.com.github.dockerjava.core.exec.AbstrSyncDockerCmdExec.exec(AbstrSyncDockerCmdExec.java:21)
    at org.testcontainers.shaded.com.github.dockerjava.core.command.AbstrDockerCmd.exec(AbstrDockerCmd.java:35)
    at org.testcontainers.containers.GenericContainer.lambda$connectToPortForwardingNetwork$5(GenericContainer.java:576)
    at org.testcontainers.containers.GenericContainer$$Lambda$119.00000000C638D020.accept(Unknown Source)
    at java.util.Optional.ifPresent(Optional.java:159)
    at org.testcontainers.containers.GenericContainer.connectToPortForwardingNetwork(GenericContainer.java:574)
    at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:413)
    at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:325)
    at org.testcontainers.containers.GenericContainer$$Lambda$97.00000000C38ED420.call(Unknown Source)
    at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
    at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:323)
    at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:311)
    at org.alvearie.keycloak.KeycloakContainerTest.<clinit>(KeycloakContainerTest.java:74)

PS. It works just fine if I manually delete the container after each run, but I was hoping it would let me continue to use the same container over and over (until I decide not to)