From 7fc458a5cdc8d6c613535cc7b5bb2da37ec1a6a9 Mon Sep 17 00:00:00 2001 From: Richard North Date: Thu, 26 Aug 2021 16:32:32 +0100 Subject: [PATCH] Use host port zero when setting up PortBindings Fixes #4395 --- .../java/org/testcontainers/containers/GenericContainer.java | 2 +- .../main/java/org/testcontainers/utility/ResourceReaper.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/testcontainers/containers/GenericContainer.java b/core/src/main/java/org/testcontainers/containers/GenericContainer.java index 50e4b927617..d00301d8394 100644 --- a/core/src/main/java/org/testcontainers/containers/GenericContainer.java +++ b/core/src/main/java/org/testcontainers/containers/GenericContainer.java @@ -753,7 +753,7 @@ private void applyConfiguration(CreateContainerCmd createCommand) { // First collect all the randomized host ports from our 'exposedPorts' field for (final Integer tcpPort : exposedPorts) { ExposedPort exposedPort = ExposedPort.tcp(tcpPort); - allPortBindings.put(exposedPort, new PortBinding(Ports.Binding.empty(), exposedPort)); + allPortBindings.put(exposedPort, new PortBinding(Ports.Binding.bindPort(0), exposedPort)); } // Next collect all the fixed host ports from our 'portBindings' field, overwriting any randomized ports so that // we don't create two bindings for the same container port. diff --git a/core/src/main/java/org/testcontainers/utility/ResourceReaper.java b/core/src/main/java/org/testcontainers/utility/ResourceReaper.java index ca657675da4..288a046ff81 100644 --- a/core/src/main/java/org/testcontainers/utility/ResourceReaper.java +++ b/core/src/main/java/org/testcontainers/utility/ResourceReaper.java @@ -107,7 +107,7 @@ public static String start(DockerClient client) { .withHostConfig( new HostConfig() .withAutoRemove(true) - .withPortBindings(new PortBinding(Ports.Binding.empty(), ryukExposedPort)) + .withPortBindings(new PortBinding(Ports.Binding.bindPort(0), ryukExposedPort)) ) .withExposedPorts(ryukExposedPort) .withName("testcontainers-ryuk-" + DockerClientFactory.SESSION_ID)