testcontainers / testcontainers/testcontainers-java

DockerComposeContainer not starting Exposed Service

Offen
#3,468 4 Kommentare 5 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

resolution/acknowledged type/bug
Vorherrschende Sprache
Java
Sterne
8.7k
Forks
1.9k
Ø Merge
2 T. 17 Std.
Gemergte PRs (30 T.)
9

Beschreibung

The latest release of testcontainers (1.15.0) seems to have introduced a bug with DockerComposeContainer where the command used to start containers is missing specified exposed services.

What happens is it seems that the docker-compose up command is missing the db service. For some reason it isn't written out as part of the command.

Command: up -d --scale scaling=2 scaled_service
Specific log: 10:34:52.774 [main] INFO 🐳 [docker-compose] - Local Docker Compose is running command: up -d --scale scaling=2 scaled_service

Example

Compose File
version: '3'

services:
  db:
    image: postgres:11
    environment:
      - POSTGRES_DB=test
      - POSTGRES_USER=test
      - POSTGRES_PASSWORD=test
    ports:
      - "5432:5432"
  scaled_service:
    image: alpine:latest
Java
import org.testcontainers.containers.DockerComposeContainer;
import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy;

import java.io.File;
import java.time.Duration;

import static java.time.temporal.ChronoUnit.SECONDS;

public class Bug {

    public static void main(final String[] args) {

        DockerComposeContainer container = new DockerComposeContainer(new File("test-compose.yml"))
                .withEnv(System.getenv())
                // Add api variable to environment to populate docker-compose port variable
                .withLocalCompose(true)
                .withScaledService("scaled_service", 2)
                .withExposedService("db", 5432, new HostPortWaitStrategy()
                        .withStartupTimeout(Duration.of(60, SECONDS)));

        container.start();

        // Will not reach this point will fail
        container.stop();
    }
}
Dependencies
<dependency>
    <groupId>org.testcontainers</groupId>
    <artifactId>testcontainers</artifactId>
    <version>1.15.0</version>
    <scope>test</scope>
</dependency>
Logs
10:45:10.981 [main] INFO  o.t.d.DockerClientProviderStrategy - Loaded org.testcontainers.dockerclient.UnixSocketClientProviderStrategy from ~/.testcontainers.properties, will try it first
10:45:11.788 [main] INFO  o.t.d.DockerClientProviderStrategy - Found Docker environment with local Unix socket (unix:///var/run/docker.sock)
10:45:11.790 [main] INFO  o.testcontainers.DockerClientFactory - Docker host IP address is localhost
10:45:11.832 [main] INFO  o.testcontainers.DockerClientFactory - Connected to docker: 
  Server Version: 19.03.13
  API Version: 1.40
  Operating System: Docker Desktop
  Total Memory: 7961 MB
10:45:11.835 [main] INFO  o.t.utility.ImageNameSubstitutor - Image name substitution will be performed by: DefaultImageNameSubstitutor (ConfigurationFileImageNameSubstitutor)
10:45:12.555 [main] INFO  o.testcontainers.DockerClientFactory - Ryuk started - will monitor and terminate Testcontainers containers on JVM exit
10:45:12.556 [main] INFO  o.testcontainers.DockerClientFactory - Checking the system...
10:45:12.556 [main] INFO  o.testcontainers.DockerClientFactory - ✔︎ Docker server version should be at least 1.6.0
10:45:12.649 [main] INFO  o.testcontainers.DockerClientFactory - ✔︎ Docker environment should have more than 2GB free disk space
10:45:12.681 [main] INFO  🐳 [docker-compose] - Local Docker Compose is running command: up -d --scale scaled_service=2 scaled_service
10:45:13.344 [Thread-3] INFO  🐳 [docker-compose] - Creating network "pqjx8ucx9yor_default" with the default driver
10:45:13.429 [Thread-3] INFO  🐳 [docker-compose] - Creating pqjx8ucx9yor_scaled_service_1 ... 
10:45:13.429 [Thread-3] INFO  🐳 [docker-compose] - Creating pqjx8ucx9yor_scaled_service_2 ... 
10:45:13.843 [Thread-3] INFO  🐳 [docker-compose] - 
10:45:13.844 [Thread-3] INFO  🐳 [docker-compose] - Creating pqjx8ucx9yor_scaled_service_1 ... done
10:45:13.853 [Thread-3] INFO  🐳 [docker-compose] - 
10:45:13.853 [Thread-3] INFO  🐳 [docker-compose] - Creating pqjx8ucx9yor_scaled_service_2 ... done
10:45:13.905 [main] INFO  🐳 [docker-compose] - 
10:45:13.905 [main] INFO  🐳 [docker-compose] - Docker Compose has finished running
10:45:13.927 [main] INFO  🐳 [alpine/socat:1.7.3.4-r0] - Creating container for image: alpine/socat:1.7.3.4-r0
10:45:13.947 [main] ERROR 🐳 [alpine/socat:1.7.3.4-r0] - Could not start container
org.testcontainers.containers.ContainerLaunchException: Aborting attempt to link to container pqjx8ucx9yor_db_1 as it is not running
	at org.testcontainers.containers.GenericContainer.applyConfiguration(GenericContainer.java:776)
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:356)
	at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:322)
	at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
	at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:320)
	at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:308)
	at org.testcontainers.containers.DockerComposeContainer.startAmbassadorContainers(DockerComposeContainer.java:330)
	at org.testcontainers.containers.DockerComposeContainer.start(DockerComposeContainer.java:177)
	at ReproduceBug.main(ReproduceBug.java:22)
Exception in thread "main" org.testcontainers.containers.ContainerLaunchException: Container startup failed
	at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:327)
	at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:308)
	at org.testcontainers.containers.DockerComposeContainer.startAmbassadorContainers(DockerComposeContainer.java:330)
	at org.testcontainers.containers.DockerComposeContainer.start(DockerComposeContainer.java:177)
	at ReproduceBug.main(ReproduceBug.java:22)
Caused by: org.rnorth.ducttape.RetryCountExceededException: Retry limit hit with exception
	at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:88)
	at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:320)
	... 4 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Could not create/start container
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:494)
	at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:322)
	at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
	... 5 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Aborting attempt to link to container pqjx8ucx9yor_db_1 as it is not running
	at org.testcontainers.containers.GenericContainer.applyConfiguration(GenericContainer.java:776)
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:356)
	... 7 more

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit DockerComposeContainer.start und dem in der Stacktrace gezeigten Zusammenbau des Befehls und vergleiche ihn anschließend mit der bereitgestellten test-compose.yml und dem Beispiel ReproduceBug.java. Führe die Reproduktion aus und überprüfe, dass die Verwendung von withExposedService db in den generierten docker-compose-Befehl aufnimmt und den Abschluss des Starts ermöglicht.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
docker, docker-compose, java, postgres
Bereich
devops, testing
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.