Skip to content

Commit

Permalink
Add support for Windows containers
Browse files Browse the repository at this point in the history
  • Loading branch information
gesellix committed Mar 11, 2024
1 parent ef43682 commit 7ce7d58
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
14 changes: 13 additions & 1 deletion core/src/main/java/org/testcontainers/DockerClientFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ static Map<String, String> markerLabels() {

private String activeApiVersion;

private boolean runningWindowsContainers;

@Getter(lazy = true)
private final boolean fileMountingSupported = checkMountableFile();

Expand Down Expand Up @@ -210,6 +212,8 @@ public void close() {
Version version = client.versionCmd().exec();
log.debug("Docker version: {}", version.getRawValues());
activeApiVersion = version.getApiVersion();
String osType = dockerInfo.getOsType();
runningWindowsContainers = StringUtils.isNotBlank(osType) && osType.equals("windows");
log.info(
"Connected to docker: \n" +
" Server Version: " +
Expand All @@ -219,7 +223,7 @@ public void close() {
activeApiVersion +
"\n" +
" Operating System: " +
dockerInfo.getOperatingSystem() +
dockerInfo.getOperatingSystem() + (runningWindowsContainers ? " (WCOW)" : "") +
"\n" +
" Total Memory: " +
dockerInfo.getMemTotal() /
Expand Down Expand Up @@ -370,6 +374,14 @@ public String getActiveApiVersion() {
return activeApiVersion;
}

/**
* @return whether the daemon is running Windows containers
*/
public boolean isRunningWindowsContainers() {
client();
return runningWindowsContainers;
}

/**
* @return the docker execution driver of the daemon that we have connected to
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ public boolean allowUserOverrides() {
}

/**
/* @return the path under which the Docker unix socket is reachable relative to the Docker daemon
*/
* @return the path under which the Docker unix socket is reachable relative to the Docker daemon
*/
public String getRemoteDockerUnixSocketPath() {
return null;
}
Expand Down Expand Up @@ -301,7 +301,7 @@ private static boolean tryOutStrategy(List<String> configurationFailures, Docker
String osType = strategy.getInfo().getOsType();
if (StringUtils.isBlank(osType)) {
log.warn("Could not determine Docker OS type");
} else if (!osType.equals("linux")) {
} else if (!osType.equals("linux") && !osType.equals("windows")) {
log.warn("{} is currently not supported", osType);
throw new InvalidConfigurationException(osType + " containers are currently not supported");
}
Expand Down
14 changes: 10 additions & 4 deletions core/src/main/java/org/testcontainers/utility/RyukContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,24 @@

class RyukContainer extends GenericContainer<RyukContainer> {

RyukContainer() {
super("testcontainers/ryuk:0.6.0");
RyukContainer(boolean runningWindowsContainers) {
super("testcontainers/ryuk:0.7.0");
withExposedPorts(8080);
withCreateContainerCmdModifier(cmd -> {
cmd.withName("testcontainers-ryuk-" + DockerClientFactory.SESSION_ID);
cmd.withHostConfig(
cmd
.getHostConfig()
.withAutoRemove(true)
.withPrivileged(TestcontainersConfiguration.getInstance().isRyukPrivileged())
.withPrivileged(TestcontainersConfiguration.getInstance().isRyukPrivileged()
&& !runningWindowsContainers)
.withBinds(
new Bind(
runningWindowsContainers
? new Bind(
"//./pipe/docker_engine",
new Volume("//./pipe/docker_engine")
)
: new Bind(
DockerClientFactory.instance().getRemoteDockerUnixSocketPath(),
new Volume("/var/run/docker.sock")
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class RyukResourceReaper extends ResourceReaper {

private final AtomicBoolean started = new AtomicBoolean(false);

private final RyukContainer ryukContainer = new RyukContainer();
private final RyukContainer ryukContainer = new RyukContainer(DockerClientFactory.instance().isRunningWindowsContainers());

@Override
public void init() {
Expand Down

0 comments on commit 7ce7d58

Please sign in to comment.