Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker-in-docker confuses getContainerIpAddress #264

Closed
Zetten opened this issue Jan 13, 2017 · 6 comments
Closed

Docker-in-docker confuses getContainerIpAddress #264

Zetten opened this issue Jan 13, 2017 · 6 comments
Assignees
Milestone

Comments

@Zetten
Copy link

Zetten commented Jan 13, 2017

I'm using testcontainers in a CI environment, where the rest of the build is itself running inside a Docker container. By having Jenkins mount /var/run/docker.sock into the container, it's possible for the in-container environment to access the docker-engine running on the host. Since our application under development is itself working with Docker for some stuff, this works great for our existing tests, e.g. building and starting containers using docker-java.

I'm also adding testcontainers to support higher-level integration testing using docker-compose. This is working fine when run directly on the host system, but our tests fail when run in the docker-in-docker environment.

The issue seems to be with the ambassador container, and that running in this environment returns the wrong host/IP when calling org.testcontainers.containers.DockerComposeContainer#getServiceHost.

Basically because this calls through to DockerClientFactory.instance().dockerHostIpAddress() it is actually just returning the location of the docker-engine, and in the Unix socket environment it shortcuts to localhost (in org.testcontainers.dockerclient.DockerClientConfigUtils#getDockerHostIpAddress). But of course in docker-in-docker localhost doesn't resolve to the correct host/interface on which the ambassador container is listening.

I'm not sure what the best solution would be... I managed to debug and try a few things which seemed to work in principle (e.g. inject as the host IP address the default gateway IP as seen inside the container, or the IP of the docker0 interface on the host) but I'm sure there's a "right" way to go about it.

@bsideup
Copy link
Member

bsideup commented Jan 13, 2017

Hey @Zetten,

I have a solution already, will backport it to TestContainers really soon, thanks for reporting!

Default gateway indeed the way to go, so I'll make TC detect docker-in-docker automatically

@Zetten
Copy link
Author

Zetten commented Jan 13, 2017

Great stuff! I'm really happy with what I've used of TestContainers - and a quick response to issues is cool too. I eagerly await the next release 😄

@bsideup
Copy link
Member

bsideup commented Jan 15, 2017

@Zetten FYI I submitted a PR with a fix.
It's not merged yet, but you can try it already, thanks to JitPack:

Add Jitpack's repo:

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

Use it:

<dependency>
    <groupId>com.github.testcontainers.testcontainers-java</groupId>
    <artifactId>testcontainers</artifactId>
    <version>docker-in-docker-SNAPSHOT</version>
</dependency>

Or just wait until it's merged :)

@Zetten
Copy link
Author

Zetten commented Jan 16, 2017

@bsideup I've given the snapshot a test and it works perfectly!

What's the expected timeframe for the next release? Just roughly for planning future work - should we expect days/weeks/months?

@bsideup
Copy link
Member

bsideup commented Jan 16, 2017

@Zetten we started to prepare 1.1.8; you can track the progress here:
https://github.com/testcontainers/testcontainers-java/milestone/19

IMO it's "days". Maybe even this week!

We plan some massive refactorings for 2.0 and would like to clean up all leftovers from 1.x, including this one :)

@bsideup
Copy link
Member

bsideup commented Jan 18, 2017

@Zetten FYI it's also possible to run your tests with --net=host if it's acceptable :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants