testcontainers / testcontainers/testcontainers-java
DockerComposeContainer not starting Exposed Service
Nessuno ha ancora preso questa issue.
- Lingua principale
- Java
- Stelle
- 8.7k
- Fork
- 1.9k
- Merge medio
- 2g 17h
- PR unite (30g)
- 9
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia da DockerComposeContainer.start e dall’assemblaggio del comando mostrato dallo stack trace, quindi confrontalo con il test-compose.yml fornito e con l’esempio ReproduceBug.java. Esegui la riproduzione e verifica che l’uso di withExposedService includa db nel comando docker-compose generato e consenta il completamento dell’avvio.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- docker, docker-compose, java, postgres
- Ambito
- devops, testing
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100