Skip to content

Commit

Permalink
Fix Docker compose stop command by adding environment (#8493)
Browse files Browse the repository at this point in the history
This issue was introduced in 7112db5. `DockerComposeContainer` and 
`ComposeContainer` now passes the env to the stop command in both 
implementations.

Fixes #8492

---------

Signed-off-by: Michael Musenbrock <michael.musenbrock@gmail.com>
Co-authored-by: Eddú Meléndez Gonzales <eddu.melendez@gmail.com>
  • Loading branch information
mmusenbr and eddumelendez authored Mar 29, 2024
1 parent eadc9d6 commit e2b2d85
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void stop() {
if (removeImages != null) {
cmd += " --rmi " + removeImages.dockerRemoveImagesType();
}
this.composeDelegate.runWithCompose(this.localCompose, cmd);
this.composeDelegate.runWithCompose(this.localCompose, cmd, this.env);
} finally {
this.project = this.composeDelegate.randomProjectId();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public void stop() {
if (removeImages != null) {
cmd += " --rmi " + removeImages.dockerRemoveImagesType();
}
this.composeDelegate.runWithCompose(this.localCompose, cmd);
this.composeDelegate.runWithCompose(this.localCompose, cmd, this.env);
} finally {
this.project = this.composeDelegate.randomProjectId();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.testcontainers.junit;

import org.junit.Rule;
import org.testcontainers.containers.ComposeContainer;

import java.io.File;

public class ComposeContainerPortViaEnvTest extends BaseComposeTest {

@Rule
public ComposeContainer environment = new ComposeContainer(
new File("src/test/resources/v2-compose-test-port-via-env.yml")
)
.withExposedService("redis-1", REDIS_PORT)
.withEnv("REDIS_PORT", String.valueOf(REDIS_PORT));

@Override
protected ComposeContainer getEnvironment() {
return environment;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.testcontainers.junit;

import org.junit.Rule;
import org.testcontainers.containers.DockerComposeContainer;

import java.io.File;

public class DockerComposeContainerPortViaEnvTest extends BaseDockerComposeTest {

@Rule
public DockerComposeContainer environment = new DockerComposeContainer(
new File("src/test/resources/v2-compose-test-port-via-env.yml")
)
.withExposedService("redis_1", REDIS_PORT)
.withEnv("REDIS_PORT", String.valueOf(REDIS_PORT));

@Override
protected DockerComposeContainer getEnvironment() {
return environment;
}
}
5 changes: 5 additions & 0 deletions core/src/test/resources/v2-compose-test-port-via-env.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
redis:
image: redis
ports:
- ${REDIS_PORT}

0 comments on commit e2b2d85

Please sign in to comment.