Skip to content

Conversation

@tisonkun
Copy link

@tisonkun tisonkun commented Dec 1, 2025

... also sync Container should reuse ContainerAsync's drop impl.

This resolves #742.

cc @DDtKey @the-wondersmith

Signed-off-by: tison <wander4096@gmail.com>
@netlify
Copy link

netlify bot commented Dec 1, 2025

Deploy Preview for testcontainers-rust ready!

Name Link
🔨 Latest commit 499d5c6
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-rust/deploys/692d43a922732600080d6777
😎 Deploy Preview https://deploy-preview-887--testcontainers-rust.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@tisonkun tisonkun mentioned this pull request Dec 1, 2025
active.runtime.block_on(async {
match active.async_impl.docker_client().config.command() {
env::Command::Remove => {
if let Err(e) = active.async_impl.rm().await {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is why containers are always removed as reported in #742 (comment)

I'm using sync Containers and its Drop impl isn't properly forwarded to the async impl.

})?;

if let Some(container_id) = client
.get_running_container_id(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, this can't handle the case where an existing container is stopped. It would then failed with:

called `Result::unwrap()` on an `Err` value: Client(CreateContainer(DockerResponseServerError { status_code: 409, message: "Conflict. The container name \"/postgres\" is already in use by container \"5d2940fb2bd042cf859598932aae34aa5004b19d38797165806282b4ada66157\". You have to remove (or rename) that container to be able to reuse that name." }))
thread 'test_simple_pubsub' panicked at tests/toolkit/src/container.rs:150:10:
called `Result::unwrap()` on an `Err` value: Client(CreateContainer(DockerResponseServerError { status_code: 409, message: "Conflict. The container name \"/postgres\" is already in use by container \"5d2940fb2bd042cf859598932aae34aa5004b19d38797165806282b4ada66157\". You have to remove (or rename) that container to be able to reuse that name." }))

I resolve this issue in my bollard based solution by removing a stopped container with the same name, but not sure how to make it more smoothly in testcontainers.

Anyway, this can be a follow-up to improved:

async fn maybe_remove_container(&self, docker: &Docker, container_name: &str) {
    let options = Some(RemoveContainerOptions {
        v: true,
        force: true,
        link: false,
    });

    // best effort to remove existing container; ignore errors
    let _ = docker.remove_container(container_name, options).await;
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stopped container

This is common when a lasting test container gets stopped during the dev machine reboot.

Signed-off-by: tison <wander4096@gmail.com>
@tisonkun
Copy link
Author

tisonkun commented Dec 1, 2025

Let me fix the format issue.

... also it seems that tests rely on selecting by labels without container name, let me try to fine tune the impl.

Signed-off-by: tison <wander4096@gmail.com>
@tisonkun
Copy link
Author

tisonkun commented Dec 1, 2025

@DDtKey failure resolved. Please help in triggering the CI.

@tisonkun
Copy link
Author

tisonkun commented Dec 1, 2025

Besides, we may later drop the "reusable-containers" flag and just deliver it by default. There is no extra dependency requirement.

@the-wondersmith
Copy link
Contributor

@tisonkun I need to dig in to confirm when I get back to my desk, but I think there's some overlap here with the fix branch I'd previously asked you to test. Come to think of it actually, I need to actually get that branch up to date with main 🤔😅.

tl;dr I'll block some time out today to give this PR a closer look, and some time this week to get that branch fixed up and get a proper PR opened.

@tisonkun
Copy link
Author

tisonkun commented Dec 3, 2025

@the-wondersmith 👍🏻

I think this PR can resolve my remaining issue now. If @DDtKey or other maintainer can get it reveiwed, you may put your changes upon this one.

That said, I'm glad to learn any concrete suggestion to improve the patch in place. And there is still a pending issue (#887 (comment)) we need to decide before testcontainers-rs can go back to my testkit ><

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reuse containers

2 participants