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

DockerComposeContainer doesn't seem to work #439

Closed
arcuri82 opened this issue Aug 11, 2017 · 12 comments
Closed

DockerComposeContainer doesn't seem to work #439

arcuri82 opened this issue Aug 11, 2017 · 12 comments

Comments

@arcuri82
Copy link

Hi,
I am trying to run DockerComposeContainer from a JUnit test, but it doesn't work. The application itself seems fine, as I can run it with no problem from command line:

docker-compose up

I set up DockerComposeContainer in my test with (in Kotlin):

companion object {

        class KDockerComposeContainer(path: File) : DockerComposeContainer<KDockerComposeContainer>(path)

        @ClassRule @JvmField
        val env = KDockerComposeContainer(File("../docker-compose.yml"))
    }

The test fails at initialization, with the following stack trace that does not really say much about what is wrong:

Connected to the target VM, address: '127.0.0.1:53858', transport: 'socket'
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
        ℹ︎ Checking the system...
        ✔ Docker version is newer than 1.6.0
        ✔ Docker environment has more than 2GB free
        ✔ File should be mountable
        ✔ Exposed port is accessible

Test ignored.

org.testcontainers.containers.ContainerLaunchException: Container startup failed

	at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:189)
	at org.testcontainers.containers.ContainerisedDockerCompose.invoke(DockerComposeContainer.java:431)
	at org.testcontainers.containers.DockerComposeContainer.runWithCompose(DockerComposeContainer.java:151)
	at org.testcontainers.containers.DockerComposeContainer.pullImages(DockerComposeContainer.java:121)
	at org.testcontainers.containers.DockerComposeContainer.starting(DockerComposeContainer.java:108)
	at org.testcontainers.containers.FailureDetectingExternalResource$1.evaluate(FailureDetectingExternalResource.java:29)
	at org.junit.rules.RunRules.evaluate(RunRules.java:20)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.rnorth.ducttape.RetryCountExceededException: Retry limit hit with exception
	at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:83)
	at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:182)
	... 12 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Could not create/start container
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:256)
	at org.testcontainers.containers.GenericContainer.lambda$start$0(GenericContainer.java:184)
	at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:76)
	... 13 more
Caused by: java.lang.IllegalStateException: Container did not start correctly.
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:231)
	... 15 more

By using a debugger, I can see it fails to start docker/compose:1.8.0. Note: I am using Windows 10, with Docker version 17.06.0-ce-win18 (12627), and TestContainers 1.4.2. TestContainers work fines in the other tests in which I have single Docker images (i.e., no Compose).

Is this a bug, or am I missing something? (In this latter case, more info in the thrown exceptions would be useful)

@bsideup
Copy link
Member

bsideup commented Aug 11, 2017

Hi @arcuri82,

Does it work if you do setLocalCompose(true) on your compose container?

@arcuri82
Copy link
Author

Hi,
thx for the very quick response. I guess you meant withLocalCompose(true) isn't it?
Anyway, the answer is "no". It seems the check

if (!CommandLine.executableExists(COMPOSE_EXECUTABLE))

in class LocalDockerCompose does not work on Windows, as checks on files on Windows need the .exe extension

@bsideup
Copy link
Member

bsideup commented Aug 11, 2017

@arcuri82 oh, very fortunate timing, we just received a PR where it's fixed :D
#437

Going to be included in the next release, but you can also try Jitpacked ( https://www.testcontainers.org/usage.html#maven-dependencies ) latest code, so far there are no major changes since the last release. Sorry for that!

@arcuri82
Copy link
Author

perfect :)

@jens-meiss
Copy link

hi i have the same problems with my new collegues, which are working on windows (don't ask why anybody would ever do this) but anyway as far as i understand the current state is that the relevant changes for windows are in the

branch, but we can't use the version from this branch because the branch is verry outdated, at least the DockerComposeContainer class is from last year and didn't have the methods

  • .withPull(false)
  • .withLocalCompose(true)

which we require.

so is there a plan when this branch gets merged into master or at least gets updated to the current state of master?

@bsideup
Copy link
Member

bsideup commented Sep 28, 2017

Hi @jens-meiss!

The problem was fixed in #437 and released a long time ago. As well as the branch you mentioned :)

Just try the latest & greatest version of TestContainers (1.4.2) :)

@jens-meiss
Copy link

@bsideup thx for the quick response, but we already using 1.4.2 and it didn't work for us on windows 10, thats the reason why i tried the version from the windows branch ...

[INFO]
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running org.test.SampleE2EITCase
2017-09-28 20:11:30.392  INFO   --- [           main] tAndSystemPropertyClientProviderStrategy : Found docker client settings from environment
2017-09-28 20:11:30.442  INFO   --- [           main] o.t.d.DockerClientProviderStrategy       : Found Docker environment with Environment variables, system properties and defaults. Resolved:
    dockerHost=tcp://127.0.0.1:2375
    apiVersion='{UNKNOWN_VERSION}'
    registryUrl='https://index.docker.io/v1/'
    registryUsername='user'
    registryPassword='null'
    registryEmail='null'
    dockerConfig='DefaultDockerClientConfig[dockerHost=tcp://127.0.0.1:2375,registryUsername=user,registryPassword=,registryEmail=,registryUrl=https://index.docker.io/v1/,dockerConfig=C:\Users\user/.docker,sslConfig=,apiVersion=...]'
2017-09-28 20:11:30.452  INFO   --- [           main] org.testcontainers.DockerClientFactory   : Docker host IP address is 127.0.0.1
2017-09-28 20:11:30.801  INFO   --- [           main] org.testcontainers.DockerClientFactory   : Connected to docker:
  Server Version: 17.06.2-ce
  API Version: 1.30
  Operating System: Alpine Linux v3.5
  Total Memory: 1987 MB
        ?? Checking the system...
        ? Docker version is newer than 1.6.0
        ? Docker environment has more than 2GB free
        ? File should be mountable
        ? Exposed port is accessible
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 9.512 s <<< FAILURE! - in org.test.SampleE2EITCase
[ERROR] org.test.SampleE2EITCase  Time elapsed: 9.511 s  <<< ERROR!
org.testcontainers.containers.ContainerLaunchException: Local Docker Compose not found. Is docker-compose on the PATH?

so it's doesn't find docker-compose command, even if you can execute it on command line

we have these docker and docker-compose version installed:

D:>docker --version
Docker version 17.06.2-ce, build cec0b72

D:>docker-compose --version
docker-compose version 1.14.0, build c7bdf9e3

@bsideup
Copy link
Member

bsideup commented Sep 28, 2017

@jens-meiss then it's #437, already in master branch, you can try it with Jitpack :)

@kiview
Copy link
Member

kiview commented Sep 29, 2017

Might also be in #461. I'll merge it and you can checkout the master branch witch Jitpack.

@jens-meiss
Copy link

@bsideup thx works with the SNAPSHOT from jitpack, hopefully we can get a released version soon, but thx anyway for the quick response! 👍 :-)

@commandini
Copy link

commandini commented Oct 11, 2017

@arcuri82 @jens-meiss For the error containing org.testcontainers.containers.ContainerLaunchException: Container startup failed ..., it's really hard to see what went wrong under the hood since the error message isn't clear enough. After a long investigation, running docker network prune worked for me. It seems there's a limit on the number of bridge networks in docker-compose and this was causing the failure of launching test containers. I hope it helps people having the same problem.

@barrycommins
Copy link
Contributor

barrycommins commented Oct 18, 2017

Hi,

#437 and #461 tried to solve similar problems around the same time and stepped on each others toes.

private static final String COMPOSE_EXECUTABLE = SystemUtils.IS_OS_WINDOWS ? "docker-compose.exe" : "docker-compose";

private boolean dockerComposeExecutableExists() {
if (SystemUtils.IS_OS_WINDOWS) {
return CommandLine.executableExists(COMPOSE_EXECUTABLE + ".exe");
} else {
return CommandLine.executableExists(COMPOSE_EXECUTABLE);
}
}

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

No branches or pull requests

6 participants