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

Container startup failed Aborting attempt to link to container as it is not running #1354

Closed
xDaDuck opened this issue Apr 2, 2019 · 3 comments
Labels

Comments

@xDaDuck
Copy link

xDaDuck commented Apr 2, 2019

Hi i have a problem with DockerComposeContainer, it fails with the following exception:

org.testcontainers.containers.ContainerLaunchException: Container startup failed
	at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:217)
	at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:199)
	at org.testcontainers.containers.DockerComposeContainer.startAmbassadorContainers(DockerComposeContainer.java:243)
	at org.testcontainers.containers.DockerComposeContainer.start(DockerComposeContainer.java:153)
	at org.testcontainers.containers.DockerComposeContainer.starting(DockerComposeContainer.java:121)
	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.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
	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:47)
	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.doStart(GenericContainer.java:210)
	... 14 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Could not create/start container
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:277)
	at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:212)
	at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:76)
	... 15 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Aborting attempt to link to container lpotl4i5hv8g_git-server_1 as it
 not running
	at org.testcontainers.containers.GenericContainer.applyConfiguration(GenericContainer.java:468)
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:228)
	... 17 more

This issue only happens on some of our developers environment, and we think is related to different docker versions.
We have been debugging the problem and have discovered that in newer version docker compose creates containers with a different container name than it is expected from testcontainers:

where the issue is present started container is named: lpotl4i5hv8g_git-server_1_edb471beb444
notice the hash at the end.

debugging further in the code i noticed that GenericContainer filters containers like this:

private Set<Link> findLinksFromThisContainer(String alias, LinkableContainer linkableContainer) {
  return dockerClient.listContainersCmd().withStatusFilter(Arrays.asList("running")).exec().stream().flatMap(container -> Stream.of(container.getNames()))
  .filter(name -> name.endsWith(linkableContainer.getContainerName()))
  .map(name -> new Link(name, alias)).collect(Collectors.toSet());
}

this method findAllNetworksForLinkedContainers has the same problem,

i could fix this in my project by copy-pasting the GenericContainer code and replacing

.filter(name -> name.endsWith(linkableContainer .getContainerName()))

with

.filter(name -> name.contains(linkableContainer .getContainerName()))

Can you please fix this?
i'm available to provide a pull request if needed.

Docker versions where it doesn't work:

Docker version 18.09.3, build 774a1f4
Server Version: 18.09.3
docker-compose version 1.23.1, build b02f1306

docker-compose.yml

version: '3.3'

services:

  git-server:
    image: cirocosta/gitserver-http
    volumes:
      - ./repos:/var/lib/initial

and this is the code that i use to start the compose:

@ClassRule
public static DockerComposeContainer dockerComposeContainer =
        new DockerComposeContainer( new File( getResource( "git-server/git-server.yml" ) ) )
                .withLocalCompose( true )
                .withExposedService( "git-server", 80 )
                .withTailChildContainers( true );

i reproduced the problem with version 1.8.0 and the latest 1.11.1

@bsideup
Copy link
Member

bsideup commented Apr 2, 2019

Hi! 1.23.1 is faulty, use newer docker-compose:
docker/compose#6316 (comment)

@stale
Copy link

stale bot commented Jul 1, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe this is a mistake, please reply to this comment to keep it open. If there isn't one already, a PR to fix or at least reproduce the problem in a test case will always help us get back on track to tackle this.

@stale stale bot added the stale label Jul 1, 2019
@stale
Copy link

stale bot commented Jul 15, 2019

This issue has been automatically closed due to inactivity. We apologise if this is still an active problem for you, and would ask you to re-open the issue if this is the case.

@stale stale bot closed this as completed Jul 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants