diff --git a/buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/configuration/ResolvedDockerHost.java b/buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/configuration/ResolvedDockerHost.java index 669a4c892cb..085aa300d57 100644 --- a/buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/configuration/ResolvedDockerHost.java +++ b/buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/configuration/ResolvedDockerHost.java @@ -59,9 +59,17 @@ public class ResolvedDockerHost extends DockerHost { public String getAddress() { String address = super.getAddress(); if (address == null) { - address = getDefaultAddress(); + return getDefaultAddress(); } - return address.startsWith(UNIX_SOCKET_PREFIX) ? address.substring(UNIX_SOCKET_PREFIX.length()) : address; + if (address.startsWith(UNIX_SOCKET_PREFIX)) { + return address.substring(UNIX_SOCKET_PREFIX.length()); + } + if (address.startsWith("tcp://")) { + while (address.endsWith("/")) { + address = address.substring(0, address.length() - 1); + } + } + return address; } public boolean isRemote() { diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/configuration/ResolvedDockerHostTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/configuration/ResolvedDockerHostTests.java index 8e4545f5f5a..703f66d83e8 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/configuration/ResolvedDockerHostTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/configuration/ResolvedDockerHostTests.java @@ -140,6 +140,17 @@ class ResolvedDockerHostTests { assertThat(dockerHost.getCertificatePath()).isEqualTo("/cert-path"); } + @Test + void resolveWhenDockerHostAddressIsTcpWithTrailingReturnsAddress() { + ResolvedDockerHost dockerHost = ResolvedDockerHost.from(this.environment::get, + new DockerConnectionConfiguration.Host("tcp://192.168.99.100:2376/", true, "/cert-path")); + assertThat(dockerHost.isLocalFileReference()).isFalse(); + assertThat(dockerHost.isRemote()).isTrue(); + assertThat(dockerHost.getAddress()).isEqualTo("tcp://192.168.99.100:2376"); + assertThat(dockerHost.isSecure()).isTrue(); + assertThat(dockerHost.getCertificatePath()).isEqualTo("/cert-path"); + } + @Test void resolveWhenEnvironmentAddressIsLocalReturnsAddress(@TempDir Path tempDir) throws IOException { String socketFilePath = Files.createTempFile(tempDir, "remote-transport", null).toAbsolutePath().toString(); @@ -180,6 +191,20 @@ class ResolvedDockerHostTests { assertThat(dockerHost.getCertificatePath()).isEqualTo("/cert-path"); } + @Test + void resolveWhenEnvironmentAddressIsTcpWithTrailingSlashReturnsAddress() { + this.environment.put("DOCKER_HOST", "tcp://192.168.99.100:2376/"); + this.environment.put("DOCKER_TLS_VERIFY", "1"); + this.environment.put("DOCKER_CERT_PATH", "/cert-path"); + ResolvedDockerHost dockerHost = ResolvedDockerHost.from(this.environment::get, + new DockerConnectionConfiguration.Host("tcp://1.1.1.1")); + assertThat(dockerHost.isLocalFileReference()).isFalse(); + assertThat(dockerHost.isRemote()).isTrue(); + assertThat(dockerHost.getAddress()).isEqualTo("tcp://192.168.99.100:2376"); + assertThat(dockerHost.isSecure()).isTrue(); + assertThat(dockerHost.getCertificatePath()).isEqualTo("/cert-path"); + } + @Test void resolveWithDockerHostContextReturnsAddress() throws Exception { this.environment.put("DOCKER_CONFIG", pathToResource("with-default-context/config.json"));