Every time I started a new Claude Code session, it would spin up fresh containers for each MCP tool. When the session ended, the containers just kept running. The –rm flag didn’t help because that only removes a container after it stops, and these containers never stop. When you Ctrl+C a docker run -i in your terminal, SIGINT gets sent, and the CLI explicitly asks the Docker daemon to stop the container. But when Claude Code exits, it just closes the stdin pipe. A closed pipe is not a signal. The docker run process dies from the broken pipe but never gets the chance to tell the daemon “please stop my container.” So the container is orphaned. Docker is doing exactly what it’s designed to do. The problem is that MCP tooling treats docker run as if it were a regular subprocess. We switched to uvx which runs the server as a normal child process and gets cleaned up on exit. Wrote up the full details and fix here: https://futuresearch.ai/blog/mcp-leaks-docker-containers/ And make sure to run docker ps | grep mcp (I found 66 containers running, all from MCP servers in my Claude Code config) submitted by /u/ddp26
Originally posted by u/ddp26 on r/ClaudeCode
