r/docker • • 3d ago

"Phantom" container processes clogging up memory on Windows Server

We're running a Windows Server host that creates runs and deletes Docker containers for development and CI/CD. All of them are Microsoft Dynamics 365 Business Central containers created with the BcContainerHelper powershell module. Every few months the host's memory gets clogged up and our main suspected cause are processes that belong to containers that no longer exist. The only fix we have found so far is rebooting the host.

When we fetch processes with 'Get-Process sqlwriter' 99% of the time we find that they match the number of container processes, the only mismatch being when we start having memory issues. This lead us to a suspicion that a container process is left hanging after container deletion or perhaps faulty creation. Has anyone else encountered a similar issue with sqlwriter processes and if so did anyone manage to resolve/prevent it?

5 Upvotes

3 comments sorted by

1

u/dawedev 3d ago

Are those process-isolated containers? Next time it starts, run hcsdiag list and see if compute systems are still there for containers docker already removed. If they are, the silo never got torn down, and hcsdiag kill <id> should free it without rebooting. Matching each sqlwriter's SessionId against live containers also tells you which ones are orphans.

1

u/Warm-Republic-1913 2d ago

To add to the hcsdiag suggestion, you can also list the sqlwriter processes with Get-CimInstance Win32_Process -Filter "Name='sqlwriter.exe'" and compare their CreationDate against the start times from docker ps, since an orphan will predate every running container. Once you have identified a stale one, Stop-Process -Id <pid> -Force is usually enough to release its memory without a host reboot. For prevention, try docker stop with a generous timeout before docker rm, so the SQL Server services inside the Business Central container shut down cleanly instead of being killed mid-shutdown. If your base image allows it, running with --isolation=hyperv gives each container its own utility VM, so nothing can be left behind on the host when the container is removed.

1

u/Free-Good9203 2d ago

One detail specific to Windows process isolation is that container processes run directly on the host kernel under a non-zero SessionId, while the host's own services sit in Session 0. When BcContainerHelper tears down a container with a force-kill instead of a clean service stop, SQL Server VSS Writer (sqlwriter.exe) can outlive the container silo and keep holding commit charge.

If you cannot switch to Hyper-V isolation yet, cap each container with an explicit memory limit at creation time and check for orphan processes whose SessionId is non-zero and no longer maps to a live container, or schedule a periodic restart of the docker and vmcompute services during a quiet CI window so leaked handles do not pile up for months.