Skip to content

Vague error message: ContainerLaunchException: Aborting attempt to link to container ${container} as it is not running #1481

@nhooey

Description

@nhooey

When starting a test, I get the following useless error messages:

org.testcontainers.containers.ContainerLaunchException: Aborting attempt to link to container 2fxwz9ug2gj2_elasticsearch_1 as it is not running
org.testcontainers.containers.ContainerLaunchException: Container startup failed

The error messages should state a reason, and have a hint for where to find more information.

In pom.xml:

    <dependency>
      <groupId>org.testcontainers</groupId>
      <artifactId>testcontainers</artifactId>
      <version>1.11.2</version>
    </dependency>

These are the functions in the test file:

package com.barrowts.omniaapi.services;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.DockerComposeContainer;
import org.testcontainers.containers.wait.strategy.Wait;

import java.io.File;

public class TestSearchService {
  private static final Logger logger = LoggerFactory.getLogger(TestSearchService.class);
  private static final int esPort = 9200;

  @RegisterExtension public static DockerComposeContainer container;

  @BeforeAll
  static void setUp() throws InterruptedException {
    container =
        new DockerComposeContainer(new File("docker/compose/elasticsearch.yaml"))
            .withLocalCompose(true)
            .withPull(false)
            .withExposedService(
                "elasticsearch", esPort, Wait.forHttp("/").forStatusCode(200).forStatusCode(401));

    logger.warn("Waiting for container");
    container.start();
    logger.warn("Done waiting for container");
  }

  @Test
  public void givenSimpleWebServerContainer_whenGetRequest_thenReturnsResponse() throws Exception {

    String address =
        String.format(
            "http://%s:%s/_health",
            container.getServiceHost("elasticsearch", esPort),
            container.getServicePort("elasticsearch", esPort));
  }
}

The Docker Compose configuration file: docker/compose/elasticsearch.yaml:

version: '2'

services:

  elasticsearch:
    container_name: omnia-elasticsearch
    image: docker.elastic.co/elasticsearch/elasticsearch:7.0.1

    build:
      context: elasticsearch
      dockerfile: Dockerfile

    environment:
      ES_HOME: "/usr/share/elasticsearch"

    ulimits:
      memlock:
        soft: -1
        hard: -1

    volumes:
      - omnia-data-elasticsearch:/usr/share/elasticsearch/data:delegated
    ports:
      - 9200:9200
    networks:
      - default

volumes:
  omnia-data-elasticsearch:
    driver: local

networks:
  default:

Full output below:

12:15:53.064 INFO  [main] o.t.d.DockerClientProviderStrategy [lambda$getFirstValidStrategy$1] Loaded org.testcontainers.dockerclient.UnixSocketClientProviderStrategy from ~/.testcontainers.properties, will try it first
12:15:53.124 INFO  [main] o.t.d.DockerClientProviderStrategy [getClientForConfig] Will use 'okhttp' transport
12:15:53.700 INFO  [main] o.t.d.UnixSocketClientProviderStrategy [test] Accessing docker with local Unix socket
12:15:53.701 INFO  [main] o.t.d.DockerClientProviderStrategy [lambda$getFirstValidStrategy$2] Found Docker environment with local Unix socket (unix:///var/run/docker.sock)
12:15:53.704 INFO  [main] o.t.DockerClientFactory [client] Docker host IP address is localhost
12:15:53.877 INFO  [main] o.t.DockerClientFactory [client] Connected to docker: 
  Server Version: 18.09.2
  API Version: 1.39
  Operating System: Docker for Mac
  Total Memory: 1999 MB
12:15:54.212 INFO  [main] o.t.u.RegistryAuthLocator [runCredentialProvider] Credentials not found for host (quay.io) when using credential helper/store (docker-credential-osxkeychain)
12:15:55.042 INFO  [main] o.t.DockerClientFactory [client] Ryuk started - will monitor and terminate Testcontainers containers on JVM exit
        ℹ︎ Checking the system...
        ✔ Docker version should be at least 1.6.0
        ✔ Docker environment should have more than 2GB free disk space
12:15:55.978 WARN  [main] c.b.o.s.TestSearchService [setUp] Waiting for container
12:15:55.985 INFO  [main] 🐳 [docker-compose] [invoke] Local Docker Compose is running command: up -d
12:15:56.554 ERROR [Thread-5] 🐳 [docker-compose] [processLine] Creating network "jshk7eydhxko_default" with the default driver
12:15:56.673 ERROR [Thread-5] 🐳 [docker-compose] [processLine] Creating volume "jshk7eydhxko_omnia-data-elasticsearch" with local driver
12:15:56.725 ERROR [Thread-5] 🐳 [docker-compose] [processLine] Creating omnia-elasticsearch ... 
12:15:57.432 ERROR [Thread-5] 🐳 [docker-compose] [processLine] 
12:15:57.433 ERROR [Thread-5] 🐳 [docker-compose] [processLine] Creating omnia-elasticsearch ... done
12:15:57.499 ERROR [main] 🐳 [docker-compose] [processLine] 
12:15:57.500 INFO  [main] 🐳 [docker-compose] [invoke] Docker Compose has finished running
12:15:57.502 INFO  [main] 🐳 [alpine/socat:latest] [tryStart] Creating container for image: alpine/socat:latest
12:15:57.574 ERROR [main] 🐳 [alpine/socat:latest] [tryStart] Could not start container
org.testcontainers.containers.ContainerLaunchException: Aborting attempt to link to container jshk7eydhxko_elasticsearch_1 as it is not running
	at org.testcontainers.containers.GenericContainer.applyConfiguration(GenericContainer.java:468) ~[testcontainers-1.11.2.jar:?]
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:228) [testcontainers-1.11.2.jar:?]
	at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:212) [testcontainers-1.11.2.jar:?]
	at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:76) [duct-tape-1.0.7.jar:?]
	at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:210) [testcontainers-1.11.2.jar:?]
	at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:199) [testcontainers-1.11.2.jar:?]
	at org.testcontainers.containers.DockerComposeContainer.startAmbassadorContainers(DockerComposeContainer.java:243) [testcontainers-1.11.2.jar:?]
	at org.testcontainers.containers.DockerComposeContainer.start(DockerComposeContainer.java:153) [testcontainers-1.11.2.jar:?]
	at com.barrowts.omniaapi.services.TestSearchService.setUp(TestSearchService.java:31) [test-classes/:?]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions