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

[Bug]: DockerComposeContainer: Stop exception when variable substitution is used in compose file #8492

Closed
mmusenbr opened this issue Mar 27, 2024 · 1 comment · Fixed by #8493
Labels

Comments

@mmusenbr
Copy link
Contributor

Module

Core

Testcontainers version

1.19.7

Using the latest Testcontainers version?

Yes

Host OS

Linux Debian/sid

Host Arch

amd64

Docker version

Client: Docker Engine - Community
 Version:           26.0.0
 API version:       1.45
 Go version:        go1.21.8
 Git commit:        2ae903e
 Built:             Wed Mar 20 15:18:01 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          26.0.0
  API version:      1.45 (minimum version 1.24)
  Go version:       go1.21.8
  Git commit:       8b79278
  Built:            Wed Mar 20 15:18:01 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.28
  GitCommit:        ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
 rootlesskit:
  Version:          2.0.2
  ApiVersion:       1.1.1
  NetworkDriver:    slirp4netns
  PortDriver:       builtin
  StateDir:         /run/user/1000/dockerd-rootless
 slirp4netns:
  Version:          1.2.1
  GitCommit:        09e31e92fa3d2a1d3ca261adaeb012c8d75a8194

What happened?

I have a docker compose file which contains a variable substitution (${VAR}). A DockerComposeContainer is created to use the compose file and set the variable a withEnv-call. This works fine, but as soon the stop is called, an Exception is thrown due to an error (IllegalStateException: Container did not start correctly.).

version: "3.9"
services:
  mock:
    image: wiremock/wiremock:3.0.3-1
    hostname: mock
  db:
    image: postgres:16
    hostname: db
networks:
  default:
    external:
      name: ${NETWORK}
Network containerNetwork = Network.newNetwork()
DockerComposeContainer composeContainer = new DockerComposeContainer("compose-file.yaml")
            .withExposedService("mock", 8080)
            .withExposedService("db", 5432)
            .withEnv("NETWORK", containerNetwork.getId());
composeContainer.start();
// .... everything fine until now
// the following stop will raise the excpeption, because inside of DockerComposeContainer#stop the env is not passed to the composeDelegate
composeContainer.stop();

Relevant log output

Caused by: org.testcontainers.containers.ContainerLaunchException: Container startup failed for image docker/compose:1.29.2
        at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:359)
        at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:330)
        at org.testcontainers.containers.ContainerisedDockerCompose.invoke(ContainerisedDockerCompose.java:64)
        at org.testcontainers.containers.ComposeDelegate.runWithCompose(ComposeDelegate.java:254)
        at org.testcontainers.containers.ComposeDelegate.runWithCompose(ComposeDelegate.java:240)
        at org.testcontainers.containers.DockerComposeContainer.stop(DockerComposeContainer.java:175)
        at my.custom.DockerComposeResource.stop(DockerComposeResource.java:142)
        at io.quarkus.test.common.TestResourceManager.close(TestResourceManager.java:177)
        ... 49 more
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:344)
        ... 56 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Could not create/start container
        at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:563)
        at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:354)
        at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
        ... 57 more
Caused by: java.lang.IllegalStateException: Container did not start correctly.
        at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:495)
        ... 59 more

Additional Information

I have a fix prepared and will open a PR.

@mmusenbr
Copy link
Contributor Author

The problem was introduced in 1.19 with commit 7112db5

mmusenbr added a commit to mmusenbr/testcontainers-java that referenced this issue Mar 27, 2024
This fixes issues on stopping when ENV-Variables are used inside the compose file.
Issue was introduced in 7112db5.

Fixes testcontainers#8492

Signed-off-by: Michael Musenbrock <michael.musenbrock@gmail.com>
mmusenbr added a commit to mmusenbr/testcontainers-java that referenced this issue Mar 27, 2024
This fixes issues on stopping when ENV-Variables are used inside the compose file.
Issue was introduced in 7112db5.

Fixes testcontainers#8492

Signed-off-by: Michael Musenbrock <michael.musenbrock@gmail.com>
eddumelendez added a commit that referenced this issue Mar 29, 2024
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant