diff --git a/core/src/main/java/org/testcontainers/utility/RyukResourceReaper.java b/core/src/main/java/org/testcontainers/utility/RyukResourceReaper.java index 999b1cbbffb..7e1b7802fb0 100644 --- a/core/src/main/java/org/testcontainers/utility/RyukResourceReaper.java +++ b/core/src/main/java/org/testcontainers/utility/RyukResourceReaper.java @@ -77,6 +77,19 @@ private synchronized void maybeStart() { ryukContainer.start(); + Runtime + .getRuntime() + .addShutdownHook( + new Thread( + DockerClientFactory.TESTCONTAINERS_THREAD_GROUP, + () -> { + this.dockerClient.killContainerCmd(this.ryukContainer.getContainerId()) + .withSignal("SIGTERM") + .exec(); + } + ) + ); + CountDownLatch ryukScheduledLatch = new CountDownLatch(1); String host = ryukContainer.getHost();