question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow for graceful container stop

See original GitHub issue

Currently I see only 1 method to stop a running testcontainer: org.testcontainers.containers.GenericContainer#stop. But to my great surprise and dismay that method ends up calling dockerClient.killContainerCmd. So there is no way for graceful shutdown of running container which would allow for the application running inside it to perform any expected cleanup.

Please, provide a graceful stop.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:10
  • Comments:17 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
bsideupcommented, May 12, 2021

There is containerIsStopping that one can use to execute stopContainerCmd. It is also possible to stop the container externally:

container.getDockerClient().stopContainerCmd(container.getContainerId()).exec();

The default timeout of 10s should be fine in most cases. Most of containers don’t need a graceful shutdown, and it would only slow down the tests.

Also note that stopping and then starting a container won’t work properly (one of the use cases for not killing the container from stop), as Docker will assign new random ports and other state adjustments. For those who want to test what happens when the process is restarted, it is recommended to restart the process inside the container and not the container itself.

Given this, I suggest we close this issue. @rnorth @kiview WDYT?

1reaction
iNikemcommented, Aug 14, 2019

I have taken a look how easy it would be for me to propose a PR. I was unable to find a suitable place for my new proposed methods. Currently container.stop delegates directly to ResourceReaper. It would be strange if the latter was able to just stop containers, without removing them. So it seems to me that my original wish is not so easy implemented.

On the other hand, in our particular case we have found a satisfying workaround (shutting applications down via Spring Boot’s actuator), so this issue does not bother us any more at all.

As a result, I suggest just closing this issue as not relevant.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Stopping Docker Containers Gracefully - Alen Komljen
Let's try to stop this container with a docker stop test . Docker will kill the container after 10 seconds. If you check...
Read more >
Graceful shutdowns with ECS | Containers - Amazon AWS
As part of the shutdown, the application should finish processing all outstanding requests and stop accepting new requests.
Read more >
Kubernetes best practices: terminating with grace
1 - Pod is set to the “Terminating” State and removed from the endpoints list of all Services. At this point, the pod...
Read more >
Kubernetes Pod Graceful Shutdown — How? | by FoxuTech
In this case, Kubernetes allows the containers running in the pod to get shutdown ... So, with this all those components updates their...
Read more >
docker - What does "gracefully stop" mean? - Stack Overflow
Additional: By stopping a container Docker send a SIGTERM to the container. I the container have not stopped in a timeout period the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found