Skip to content

Allow configuration on container if it should be automatically cleaned up #850

@cbrevik

Description

@cbrevik

In reference to #849 (comment) I'd like to be able to override the default behaviour where a container is cleaned up when it is stopped.

What I suggest is adding a new function on GenericContainer:

  • withRemoveWhenStopped(removeWhenStopped: boolean)

So the default behaviour is still that the container is removed when you call container.stop(). But to override you can explicitly configure it with .withRemoveWhenStopped(false) when creating the container. It should probably still be possible to override the configured value by options container.stop({ remove: true }).

It also made sense to me that you'd to be able to configure withAutoRemove(autoRemove: boolean), so if the container is stopped in other ways than via the testcontainers-node API it is also cleaned up.

I've taken a stab at adding both withRemoveWhenStopped and withAutoRemove here (including tests): main...cbrevik:testcontainers-node:support-configured-auto-remove

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