Docker compose is not shutting down when application exits
smifun opened this issue · 7 comments
Hi,
I noticed that when I'm running test with DockerComposeRule in debug mode and then terminate application, docker compose still running, this is causing failure to run/debug test again due to port binding. (I know I could randomise ports). This requires manual shutdown of containers.
I'm guessing that's because terminating test is not running "after" method on rule. Maybe implementing Shutdown hook to run "after" section could help.
Regards Kamil
Its even worse on build server it's leaving containers running If I would use random ports, it would result in container creation bomb.
I also experience this problem. We had our own docker integration before which solved this problem. There we used a separate process to start and stop the docker containers. The main process created a temp file that it touched in regular intervals in a thread. The process taking care of docker watched that file and if the file got stale or was going away the docker control process shuts down docker and ends itself. This was working very reliably. I wonder if we could apply this approach for docker-compose rule too.
If there is interest I can work on a PR.
+1
It's the only critical bug I experience
@felixdesouza / @fryz we might want to consider adding something to the core lifecycle of the Docker Compose object instead of just having duplicate code for the beforeAll
method in JUnit4 and JUnit5
com.palantir.docker.compose.DockerComposeRule seems to always use the default/constant shutdown strategy even if you mention a different strategy during building the compose rule.
The above method is being called from after method that is executed after executing the test cases.