Skip to content

Commit fcb4481

Browse files
jochenhebbrechtbsideup
authored andcommitted
Make sure the Docker Host IP address is retrieved correctly when running inside docker (#541)
* fix: introduce 'withFollowStream' and 'awaitCompletion' methods to await the completion of one-off command * Fixed retrieval of Docker host IP when running inside Docker (#479) * fix: withStdErr() is not needed - withTailAll() is not needed (default: tail=all) * Update CHANGELOG.md
1 parent 4e79301 commit fcb4481

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
### Fixed
5+
- Fixed retrieval of Docker host IP when running inside Docker. ([\#479](https://github.com/testcontainers/testcontainers-java/issues/479))
6+
47
## [1.5.1] - 2017-12-19
58

69
### Fixed

core/src/main/java/org/testcontainers/dockerclient/DockerClientConfigUtils.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import java.io.File;
1010
import java.util.Optional;
1111

12+
import static java.util.concurrent.TimeUnit.SECONDS;
13+
1214
@Slf4j
1315
public class DockerClientConfigUtils {
1416

@@ -23,10 +25,13 @@ public class DockerClientConfigUtils {
2325
cmd -> cmd.withCmd("sh", "-c", "ip route|awk '/default/ { print $3 }'"),
2426
(client, id) -> {
2527
try {
26-
return client.logContainerCmd(id)
27-
.withStdOut(true)
28-
.exec(new LogToStringContainerCallback())
29-
.toString();
28+
LogToStringContainerCallback loggingCallback = new LogToStringContainerCallback();
29+
client.logContainerCmd(id).withStdOut(true)
30+
.withFollowStream(true)
31+
.exec(loggingCallback)
32+
.awaitStarted();
33+
loggingCallback.awaitCompletion(3, SECONDS);
34+
return loggingCallback.toString();
3035
} catch (Exception e) {
3136
log.warn("Can't parse the default gateway IP", e);
3237
return null;

0 commit comments

Comments
 (0)