Skip to content

Lambda container not being removed automatically #848

Closed
@ksiczek

Description

@ksiczek

Hi there!

I was doing some testing with Testcontainers and LocalStack. I created a container as the docs say, but it turned out that when I stopped it, the lambda container was left started. I found a similar issue in the Java implementation so I tried porting it to my Node solution, ending up with something like:

before(async () => {
    const resourceReaper = await getContainerRuntimeClient().then(crc => getReaper(crc))
    container = await new LocalstackContainer('localstack/localstack:latest')
        .withEnvironment(
            {
                SERVICES: 's3,lambda',
                EAGER_SERVICE_LOADING: '1'
            }
        )
        // below is needed so the lambda service could create a docker image for itself
        .withBindMounts([{
            source: "/var/run/docker.sock",
            target: "/var/run/docker.sock"
        }])
        .withEnvironment(
            {
                /**
                 * Localstack lambda spins a new Docker container up but the container is not removed by
                 * Testcontainers resource reaper unless we pass a label indicating the session id. 
                 */
                LAMBDA_DOCKER_FLAGS: `-l org.testcontainers.session-id=${resourceReaper.sessionId}`
            }
        )
        .start();

[...]
})

Can you make this out-of-the-box solution, please? I found those orphan containers only because I started having issues with resources and it seems the LocalStack has no way to integrate with the resource reaper. If not, then maybe you could mention this in the docs? WDYT?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions