Skip to content

[Bug]: LocalStackContainer is deleted after test when withReuse is true #7097

Description

@axeleroy

Module

LocalStack

Testcontainers version

1.18.3

Using the latest Testcontainers version?

Yes

Host OS

Linux

Host Arch

x86

Docker version

Client: Docker Engine - Community
 Version:           24.0.2
 API version:       1.43
 Go version:        go1.20.4
 Git commit:        cb74dfc
 Built:             Thu May 25 21:52:22 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          24.0.2
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.4
  Git commit:       659604f
  Built:            Thu May 25 21:52:22 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.21
  GitCommit:        3dce8eb055cbb6872793272b4f20ed16117344f8
 runc:
  Version:          1.1.7
  GitCommit:        v1.1.7-0-g860f061
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

What happened?

I'm trying to debug my LocalStack container in a CI environment and for that I would like it to not be deleted after the tests so I can read its logs after.

I followed the steps described in the doc, which means opting-in Reusable Containers (testcontainers.reuse.enable=true in ~/.testcontainers.properties), adding withReuse(true) and starting the container manually:

LocalStackContainer localStackContainer =
    new LocalStackContainer(DockerImageName.parse("localstack/localstack:2.0.2"))
        .withServices(
            Service.DYNAMODB,
            LocalStackContainer.EnabledService.named("events")
        )
        .withClasspathResourceMapping("testcontainers/init-scripts", "/etc/localstack/init/ready.d",
            BindMode.READ_ONLY)
        .withEnv("DEBUG", "1")
        .withEnv("HOSTNAME", "localstack")
        .withEnv("HOSTNAME_EXTERNAL", "localstack")
        .withEnv("SKIP_SSL_CERT_DOWNLOAD", "true")
        .waitingFor(Wait
            .forLogMessage(".*localstack just finished starting.*", 1))
        .withStartupTimeout(Duration.ofMinutes(10))
        .withReuse(true);
localStackContainer.start();

But unfortunately, after the tests ran, docker ps -a doesn't show any localstack container.

Relevant log output

No response

Additional Information

We are using Gradle and Junit Jupiter on a Spring Boot 2.7 project

implementation "org.testcontainers:testcontainers:1.18.3"
implementation "org.testcontainers:junit-jupiter:1.18.3"
implementation "org.testcontainers:localstack:1.18.3"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions