Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker Containers do not get cleaned up after successfull test run #353

Closed
Pinguwien opened this issue Dec 29, 2020 · 3 comments
Closed
Labels
question Have you tried our Slack workspace (https://testcontainers.slack.com)?

Comments

@Pinguwien
Copy link

Pinguwien commented Dec 29, 2020

Describe the bug
I am fiddling around with a small testcontainers example app using .net core 5.0.101 and latest rider IDE on OSX 10.15.7

(no M1).

I tried to use the WithName method on my postgrescontainer. The tests are successfully running, but failing the second time I run them.
It seems the WithCleanup-Method does not get called correctly (anymore?)

To Reproduce
Steps to reproduce the behavior:

  1. Create new project
  2. add testcontainer with 'WithName' and 'WithCleanup(true)'
  3. Run tests more than once
  4. Error coming up: OneTimeSetUp: Docker.DotNet.DockerApiException : Docker API responded with status code=Conflict, response={"message":"Conflict. The container name \"/test\" is already in use by container \"6414b598be12718f4061736e8feccefac26ff0402c45ff4c41152bd1d0ec481c\". You have to remove (or rename) that container to be able to reuse that name."}

the commands docker container ls -a and docker volume ls are showing the not cleaned-up container afterards and they have to be pruned manually.

I added a video to show the behaviour.

Expected behavior
Docker Container created by TestContainers gets cleaned up correctly

Screenshots
see video here (10mb limit at github, so uploaded to yt instead for HD): https://www.youtube.com/watch?v=YdJ59LX5Kjc

Desktop (please complete the following information):

  • Testcontainers v 1.5.0-beta.20201201.11
  • OSX 10.15.7
  • Rider 2020.2
  • .Net Core SDK 5.0.101
  • Docker for Mac w/ engine v20.10.0

Additional context
I am using NUnits OneTimeSetup and OneTimeTearDown together with testcontainers StartAsync / StopAsync - could that be a problem? (see code in video) edit: No, doesnt have something to do with the onetime-attributes. tried it in another namespace with normal setup/teardown, same behaviour. 2 unit tests, 2 new containers/volumes that do not get cleaned afterwards.

Feel free to reach out for help. I'd be happy to debug this myself (or pairing with you) and see if I could fix it, but tbh I have no clue on how to add the testcontainers code to my project the right way to get it to work(tried once, failed).

@HofmeisterAn
Copy link
Collaborator

HofmeisterAn commented Dec 29, 2020

As far as I can see, you do not call Dispose in your code. You have to dispose either with the using block or call it manual. Otherwise, the container won't be removed. Also notice following behavior #242. To avoid #242 we could persist the containers in TestcontainersRegistryService and remove them at the first start or use something like the ResourceReaper.

@HofmeisterAn HofmeisterAn added the question Have you tried our Slack workspace (https://testcontainers.slack.com)? label Dec 29, 2020
@Pinguwien
Copy link
Author

argh... i hate myself and... well. with dispose everything works as intended. nvm :D I saw the other issue, but mine was slightly different (due to classical layer 8 as it turns out). Thanks for the quick response! :)

@Pinguwien
Copy link
Author

closing issue due to my fault. meh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Have you tried our Slack workspace (https://testcontainers.slack.com)?
Projects
None yet
Development

No branches or pull requests

2 participants