Skip to content

stop() fails on a container started with withAutoRemove(true) #76

Closed

Description

@AdzerKI

A container started with withAutoRemove(true) is removed by the daemon as soon as it exits. StartedGenericContainer::stop() still calls containerDelete() after containerStop(), so it races with the daemon and throws ContainerDeleteNotFoundException (or a 409 "removal already in progress" on Docker) when the daemon wins.

We hit it in a register_shutdown_function(fn () => $container->stop()) with a MySQL container:

PHP Fatal error:  Uncaught Docker\API\Exception\ContainerDeleteNotFoundException: no such container
#3 vendor/testcontainers/testcontainers/src/Container/StartedGenericContainer.php(82): Docker\API\Client->containerDelete()

withAutoRemove() came in #60, but stop() was not updated for it.

Fix: stop() reads HostConfig.AutoRemove from the inspect response and skips the delete when it is set. PR follows.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions