Skip to content

Commit

Permalink
Use host port zero when setting up PortBindings
Browse files Browse the repository at this point in the history
Fixes #4395
  • Loading branch information
rnorth committed Aug 26, 2021
1 parent 1699e47 commit 7fc458a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7fc458a

Please sign in to comment.