# How does Docker stop containers on Windows?

**URL:** <https://forums.docker.com/t/how-does-docker-stop-containers-on-windows/20882>\
**Category:** Docker Desktop\
**Tags:** windows\
**Created:** [August 22, 2016, 5:02pm UTC](https://forums.docker.com/t/how-does-docker-stop-containers-on-windows/20882 "2016-08-22T17:02:54Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![godefroi](https://avatars.discourse-cdn.com/v4/letter/g/d78d45/32.png) [@godefroi](https://forums.docker.com/u/godefroi)\
**Post date:** [August 22, 2016, 5:02pm UTC](https://forums.docker.com/t/how-does-docker-stop-containers-on-windows/20882/1 "2016-08-22T17:02:54Z")

</div>

I’m using Docker (Docker version 1.12.0, build 8eab29e) on Server 2016 TP5, and I cannot figure out how I can gracefully shut down a container. On Linux, “docker stop” will send SIGTERM to the process, and after 10 (by default) seconds, will send SIGKILL. On Windows, however, this must be different.

I have tried SetConsoleCtrlHandler, but my handler was not called.

I have tried calling signal(…) from MSVCRT, but it seems SIGTERM isn’t being received.

How can I detect that Docker wants to stop my application, so I can gracefully shut down?

---

<div class="post-metadata">

**Author:** ![friism](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/friism/32/3570_2.png) [@friism](https://forums.docker.com/u/friism)\
**Post date:** [August 24, 2016, 2:51am UTC](https://forums.docker.com/t/how-does-docker-stop-containers-on-windows/20882/2 "2016-08-24T02:51:36Z")

</div>

Have you tried to get this working outside of a container? The process running on the Windows Docker container should see the behavior as a normal Windows process (I don’t actually know exactly what that is).

---

<div class="post-metadata">

**Author:** ![friism](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/friism/32/3570_2.png) [@friism](https://forums.docker.com/u/friism)\
**Post date:** [August 24, 2016, 3:51am UTC](https://forums.docker.com/t/how-does-docker-stop-containers-on-windows/20882/3 "2016-08-24T03:51:11Z")

</div>

The code is here: [https://github.com/docker/docker/blob/4a7bd7eaef0038b006cf23adface84081e5aab3b/pkg/signal/signal\_windows.go#L19](https://github.com/docker/docker/blob/4a7bd7eaef0038b006cf23adface84081e5aab3b/pkg/signal/signal_windows.go#L19)

---

<div class="post-metadata">

**Author:** ![godefroi](https://avatars.discourse-cdn.com/v4/letter/g/d78d45/32.png) [@godefroi](https://forums.docker.com/u/godefroi)\
**Post date:** [August 24, 2016, 4:52am UTC](https://forums.docker.com/t/how-does-docker-stop-containers-on-windows/20882/4 "2016-08-24T04:52:26Z")

</div>

> [@friism](#):
>
> Have you tried to get this working outside of a container? The process running on the Windows Docker container should see the behavior as a normal Windows process (I don’t actually know exactly what that is).

Well, that’s exactly the question. What a “normal Windows process” sees depends entirely on how it is terminated. Just as a Linux process might receive SIGTERM, or SIGKILL, there are several ways to end a Windows process. If it has a message loop, you might send a WM\_CLOSE message, or if the process has a stdio handle, you might send CTRL-C to it. You might simulate an OS shutdown, which would result in a different message being received. From my experimentation, it seems that “docker stop” is doing essentially a TerminateProcess, or the Windows equivalent of SIGKILL. This is bad.

The best discussion I found [was here](https://groups.google.com/a/opencontainers.org/d/msg/dev/PlGKu7QUwLE/juMXbbMYDAAJ), but the real question, then, is “what is behind hcsshim.ShutdownComputeSystem”? Apparently (from zhcsshim.go) it’s calling “ShutdownComputeSystem” from vmcompute.dll, but that doesn’t help much.

---

<div class="post-metadata">

**Author:** ![friism](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/friism/32/3570_2.png) [@friism](https://forums.docker.com/u/friism)\
**Post date:** [August 24, 2016, 5:06am UTC](https://forums.docker.com/t/how-does-docker-stop-containers-on-windows/20882/5 "2016-08-24T05:06:42Z")

</div>

That’s calling the Windows containerization APIs. You can open an issue on `docker/docker` and ping John Howard if you have ideas for improvements.

---

<div class="post-metadata">

**Author:** ![godefroi](https://avatars.discourse-cdn.com/v4/letter/g/d78d45/32.png) [@godefroi](https://forums.docker.com/u/godefroi)\
**Post date:** [August 24, 2016, 2:17pm UTC](https://forums.docker.com/t/how-does-docker-stop-containers-on-windows/20882/6 "2016-08-24T14:17:38Z")

</div>

I believe that the code that ultimately gets called is MS code here. I’ll open an issue and ping John. Thanks for the pointer, I appreciate it.

---

<div class="post-metadata">

**Author:** ![abrarov](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/abrarov/32/13936_2.png) [@abrarov](https://forums.docker.com/u/abrarov)\
**Post date:** [October 15, 2016, 1:49pm UTC](https://forums.docker.com/t/how-does-docker-stop-containers-on-windows/20882/7 "2016-10-15T13:49:19Z")

</div>

Hi. Was this question / issue resolved? I’m interested in running [my console app](https://hub.docker.com/r/abrarov/tcp_echo_win/) in a Docker container (Windows Containers) and it seems (according to console output - `docker logs`) that application is terminated or stopped somehow (`docker stop -t 120`) but I need to emulate Ctrl-C / Ctrl-Break for graceful shutdown (while Docker for Windows Containers doesn’t support `STOPSIGNAL` directive in Dockerfile - it explicitly refuses to build images with `STOPSIGNAL` and states that this feature is not supported).

---

<div class="post-metadata">

**Author:** ![godefroi](https://avatars.discourse-cdn.com/v4/letter/g/d78d45/32.png) [@godefroi](https://forums.docker.com/u/godefroi)\
**Post date:** [October 15, 2016, 2:38pm UTC](https://forums.docker.com/t/how-does-docker-stop-containers-on-windows/20882/8 "2016-10-15T14:38:59Z")

</div>

As far as I can tell, with the current (release) version, the process is  
stopped using TerminateProcess().

---

<div class="post-metadata">

**Author:** ![jformacek](https://avatars.discourse-cdn.com/v4/letter/j/a4c791/32.png) [@jformacek](https://forums.docker.com/u/jformacek)\
**Post date:** [March 1, 2017, 4:08pm UTC](https://forums.docker.com/t/how-does-docker-stop-containers-on-windows/20882/9 "2017-03-01T16:08:08Z")

</div>

Hello,  
has this issue been resolved meanwhile? I’m developing service that needs to perform cleanup tasks on network during shutdown, so would be great to have a way to get notified for container stop event in order to perform graceful shutdown.

Thanks,  
Jiri

---

<div class="post-metadata">

**Author:** ![godefroi](https://avatars.discourse-cdn.com/v4/letter/g/d78d45/32.png) [@godefroi](https://forums.docker.com/u/godefroi)\
**Post date:** [March 2, 2017, 6:09pm UTC](https://forums.docker.com/t/how-does-docker-stop-containers-on-windows/20882/10 "2017-03-02T18:09:32Z")

</div>

Not as far as I can tell. [The docker issue is here](https://github.com/docker/docker/issues/25982), and one PR was merged in, but it’s still waiting for “platform changes”. [There are rumours](https://twitter.com/WZorNET/status/829684774386200576) that Server 2016 RS2 won’t be released, and if this got pushed to RS3, we could be waiting until fall 2017 for the fix. Sadface.
