Skip to content

Commit 40cdd58

Browse files
authored
Make it possible to turn off Ryuk with an environment variable (#1181)
* Make it possible to turn off Ryuk with an environment variable * Reverse the condition * Document how to disable the Ryuk
1 parent 7b2dd01 commit 40cdd58

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

core/src/main/java/org/testcontainers/DockerClientFactory.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,35 @@ public DockerClient client() {
119119
" Operating System: " + dockerInfo.getOperatingSystem() + "\n" +
120120
" Total Memory: " + dockerInfo.getMemTotal() / (1024 * 1024) + " MB");
121121

122-
boolean checksEnabled = !TestcontainersConfiguration.getInstance().isDisableChecks();
123-
124-
String ryukContainerId = ResourceReaper.start(hostIpAddress, client, checksEnabled);
125-
log.info("Ryuk started - will monitor and terminate Testcontainers containers on JVM exit");
122+
String ryukContainerId = null;
123+
boolean useRyuk = !Boolean.parseBoolean(System.getenv("TESTCONTAINERS_RYUK_DISABLED"));
124+
if (useRyuk) {
125+
ryukContainerId = ResourceReaper.start(hostIpAddress, client);
126+
log.info("Ryuk started - will monitor and terminate Testcontainers containers on JVM exit");
127+
}
126128

127129
VisibleAssertions.info("Checking the system...");
128130

129131
checkDockerVersion(version.getVersion());
130132

133+
boolean checksEnabled = !TestcontainersConfiguration.getInstance().isDisableChecks();
131134
if (checksEnabled) {
132-
checkDiskSpace(client, ryukContainerId);
135+
if (ryukContainerId != null) {
136+
checkDiskSpace(client, ryukContainerId);
137+
} else {
138+
runInsideDocker(
139+
client,
140+
createContainerCmd -> {
141+
createContainerCmd.withName("testcontainers-checks-" + SESSION_ID);
142+
createContainerCmd.getHostConfig().withAutoRemove(true);
143+
createContainerCmd.withCmd("tail", "-f", "/dev/null");
144+
},
145+
(__, containerId) -> {
146+
checkDiskSpace(client, containerId);
147+
return "";
148+
}
149+
);
150+
}
133151
}
134152

135153
initialized = true;

docs/features/configuration.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,20 @@ Some companies disallow the usage of Docker Hub, but you can override `*.image`
4242
> **kafka.container.image = confluentinc/cp-kafka**
4343
> Used by KafkaContainer
4444
45-
## Customizing ryuk resource reaper
45+
## Customizing Ryuk resource reaper
4646

4747
> **ryuk.container.image = quay.io/testcontainers/ryuk:0.2.2**
4848
> The resource reaper is responsible for container removal and automatic cleanup of dead containers at JVM shutdown
4949
5050
> **ryuk.container.privileged = false**
5151
> In some environments ryuk must be started in privileged mode to work properly (--privileged flag)
5252
53+
### Disabling Ryuk
54+
Ryuk must be started as a privileged container.
55+
If your environment already implements automatic cleanup of containers after the execution,
56+
but does not allow starting privileged containers, you can turn off the Ryuk container by setting
57+
`TESTCONTAINERS_RYUK_DISABLED` **environment variable** to `true`.
58+
59+
!!!tip
60+
Note that Testcontainers will continue doing the cleanup at JVM's shutdown, unless you `kill -9` your JVM process.
61+

0 commit comments

Comments
 (0)