docker-compose-rule icon indicating copy to clipboard operation
docker-compose-rule copied to clipboard

Docker compose is not shutting down when application exits

Open smifun opened this issue 7 years ago • 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

smifun avatar Oct 30 '17 10:10 smifun

Its even worse on build server it's leaving containers running If I would use random ports, it would result in container creation bomb.

smifun avatar Nov 03 '17 09:11 smifun

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.

cschneider avatar Feb 26 '18 08:02 cschneider

+1

It's the only critical bug I experience

galvinograd avatar Mar 21 '18 14:03 galvinograd

I think this is somewhat related to (and or, solution might fix) https://github.com/palantir/docker-compose-rule/issues/165

fryz avatar Apr 20 '18 19:04 fryz

I've typically found myself doing this in a few places to get past this very problem:

Runtime.getRuntime().addShutdownHook(new Thread(composition::after);

It might be worth adding by default to the before.

On Fri, 20 Apr 2018 at 20:07 Zach Fry [email protected] wrote:

I think this is somewhat related to (and or, solution might fix) #165 https://github.com/palantir/docker-compose-rule/issues/165

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/palantir/docker-compose-rule/issues/216#issuecomment-383193350, or mute the thread https://github.com/notifications/unsubscribe-auth/AET9CfPS72r1DnkqpLp1fxr-ORV4rUjUks5tqjIJgaJpZM4QK838 .

felixdesouza avatar Apr 20 '18 20:04 felixdesouza

@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

dotCipher avatar Apr 30 '18 21:04 dotCipher

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. https://github.com/palantir/docker-compose-rule/blob/a584cb38cbc7f48e497b686358e1a656a95ecd53/docker-compose-rule-junit4/src/main/java/com/palantir/docker/compose/DockerComposeRule.java#L93

The above method is being called from after method that is executed after executing the test cases. https://github.com/palantir/docker-compose-rule/blob/a584cb38cbc7f48e497b686358e1a656a95ecd53/docker-compose-rule-junit4/src/main/java/com/palantir/docker/compose/DockerComposeRule.java#L160

saikatmohajan avatar Sep 11 '18 16:09 saikatmohajan