Skip to content

Commit 39f0219

Browse files
authored
Add shutdownHook to send sigterm to ryuk (#7717)
Currently, `Ryuk` container finishes after around 10s. This commit register a shutdown hook which will send a sigterm to the Ryuk container when JVM is terminating causing Ryuk to finish sooner.
1 parent 95849a5 commit 39f0219

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

core/src/main/java/org/testcontainers/utility/RyukResourceReaper.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,19 @@ private synchronized void maybeStart() {
7777

7878
ryukContainer.start();
7979

80+
Runtime
81+
.getRuntime()
82+
.addShutdownHook(
83+
new Thread(
84+
DockerClientFactory.TESTCONTAINERS_THREAD_GROUP,
85+
() -> {
86+
this.dockerClient.killContainerCmd(this.ryukContainer.getContainerId())
87+
.withSignal("SIGTERM")
88+
.exec();
89+
}
90+
)
91+
);
92+
8093
CountDownLatch ryukScheduledLatch = new CountDownLatch(1);
8194

8295
String host = ryukContainer.getHost();

0 commit comments

Comments
 (0)