From 3c30a267d1bb678dba13a17c5ccfd53eef4824e7 Mon Sep 17 00:00:00 2001 From: vincz7777 <96777535+vincz7777@users.noreply.github.com> Date: Wed, 5 Jan 2022 11:24:37 +0100 Subject: [PATCH] Display Ryuk logs when it fails to start (#4842) Co-authored-by: Sergei Egorov Co-authored-by: Vincent MIJOULE (contractor) Co-authored-by: Richard North --- .../utility/ResourceReaper.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/org/testcontainers/utility/ResourceReaper.java b/core/src/main/java/org/testcontainers/utility/ResourceReaper.java index 8c1f28378ef..f43835fd01b 100644 --- a/core/src/main/java/org/testcontainers/utility/ResourceReaper.java +++ b/core/src/main/java/org/testcontainers/utility/ResourceReaper.java @@ -34,7 +34,6 @@ import java.net.Socket; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; -import java.time.Duration; import java.util.AbstractMap.SimpleEntry; import java.util.ArrayList; import java.util.Collections; @@ -133,10 +132,10 @@ public void onNext(Frame frame) { } }); - ContainerState containerState = new ContainerState() { - + InspectContainerResponse inspectedContainer; + try { // inspect container response might initially not contain the mapped port - final InspectContainerResponse inspectedContainer = await() + inspectedContainer = await() .atMost(5, TimeUnit.SECONDS) .pollInterval(DynamicPollInterval.ofMillis(50)) .pollInSameThread() @@ -144,14 +143,20 @@ public void onNext(Frame frame) { () -> client.inspectContainerCmd(ryukContainerId).exec(), inspectContainerResponse -> { return inspectContainerResponse - .getNetworkSettings() - .getPorts() - .getBindings() - .values() - .stream() - .anyMatch(Objects::nonNull); + .getNetworkSettings() + .getPorts() + .getBindings() + .values() + .stream() + .anyMatch(Objects::nonNull); } ); + } catch (Exception e) { + log.warn("Ryuk container cannot be inspected and probably had a problem starting. Ryuk's logs:\n{}", ryukLog); + throw new IllegalStateException("Ryuk failed to start", e); + } + + ContainerState containerState = new ContainerState() { @Override public List getExposedPorts() {