From a314e01434e7010e4999faa93d9bd017a92742a1 Mon Sep 17 00:00:00 2001 From: ericlapier <157530298+ericlapier@users.noreply.github.com> Date: Tue, 23 Jan 2024 17:14:39 -0500 Subject: [PATCH] Port Bindings is not respected for SSH port 1- Dashboard > Manage Jenkins > Configure Clouds 2- Add a new Cloud 3- Connect method SSH 4- Container settings 5- Port Bindings 0.0.0.0:20000-20100:22 Expected Results All docker-proxy process should use a port between 20000 and 20100 Tested for a year now with this fix and docker-proxy always gets a port in the specified range. --- .../docker/connector/DockerComputerSSHConnector.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/jenkins/docker/connector/DockerComputerSSHConnector.java b/src/main/java/io/jenkins/docker/connector/DockerComputerSSHConnector.java index 029d2bc2d..b816e3fc4 100644 --- a/src/main/java/io/jenkins/docker/connector/DockerComputerSSHConnector.java +++ b/src/main/java/io/jenkins/docker/connector/DockerComputerSSHConnector.java @@ -278,8 +278,10 @@ public void beforeContainerCreated(DockerAPI api, String workdir, CreateContaine } final Ports portBindings = hostConfig.getPortBindings(); if (portBindings != null) { - portBindings.add(sshPortBinding); - hostConfig.withPortBindings(portBindings); + if(portBindings.getBindings().get(sshPortBinding.getExposedPort()).length == 0) { + portBindings.add(sshPortBinding); + hostConfig.withPortBindings(portBindings); + } } else { hostConfig.withPortBindings(sshPortBinding); }