testcontainers-java: Ryuk container name already in use

The error message from docker is:

Conflict. The container name "/testcontainers-ryuk-181a7bc5-71b4-41c5-89ee-b5f0b0f378ed" is already in use by container "7b89e6644ce929b67b9934dd1caf2b414f98e7143490b20d2cdcc36645c60830". You have to remove (or rename) that container to be able to reuse that name.

Based on looking through the code, you are creating a static SESSION_ID in the DockerClientFactory but you are creating a Ryuk container per docker client. There isn’t a check for an existing container with that id.

I’m not sure what the correct solution is. The 2 options I see are:

  • have a per-client session id
  • handle the container already existing by checking and returning the id

We are using version 1.12.5

This happens during CI builds using docker-in-docker on BuildKite. EC2 hosts running Amazon Linux. Does not happen locally on macOS or on linux laptops.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 6
  • Comments: 26 (11 by maintainers)

Commits related to this issue

Most upvoted comments

Also affected by this. Same setup.

Okay, after looking at the code, I noticed that we were not caching Ryuk’s failure: #2935

So, the actual problem was that ResourceReaper was failing to connect to started Ryuk container, but another attempt at getting a client would not know that and attempt to start it again.

This logs confirms that: https://pastebin.com/pZHXKzRF

Caused by: java.lang.IllegalStateException: Can not connect to Ryuk

My tests worked fine on 1.12.4, but start to fail 1.13.0 with this error. Also running docker-in-docker.

Please reopen. I am having this issue on a very uncomplicated “hello world” type of project, rendering the TestContainers library unusable at the moment.

Apr 26, 2021 3:06:41 PM org.junit.jupiter.engine.execution.JupiterEngineExecutionContext close SEVERE: Caught exception while closing extension context: org.junit.jupiter.engine.descriptor.ClassExtensionContext@d72284c com.github.dockerjava.api.exception.ConflictException: Status 409: {“message”:“Conflict. The container name "/testcontainers-ryuk-f3039b1f-d175-4c4f-981b-aca78f782347" is already in use by container "882f294ea3178cf5d254e78f782e73ee8bd53430d4388b5ecaffab3a9e81ae5b". You have to remove (or rename) that container to be able to reuse that name.”}

My Gradle build file:

largeTestImplementation ‘org.testcontainers:junit-jupiter:1.15.3’ largeTestImplementation ‘org.testcontainers:postgresql:1.15.3’

My machine is a Hyper-V virtual machine (Windows 10 x64) running Docker (20.10.5) on WSL2 (which technically becomes a nested VM). WSL2’s distro is Ubuntu 20.04.

Desperately awaiting a release version with these fixes included (Jenkins here).

@aguibert FYI I just submitted https://github.com/testcontainers/testcontainers-java/pull/2930 that should fix eager resolve of LazyFuture from RemoteDockerImage#toString (that is triggered from GenericContainer#toString, for example). It is unrelated to the Ryuk problem but seems to be a miss from #2558

BTW from the stacktrace, it looks like you’re using a version that is older that 1.14.x, consider updating.

Affected by this using version 1.13.0