展示HN:为您的代理运行多个Docker Compose实例
大家好。
在使用 Docker Compose 设置运行多个代理和 Git 工作树时,我不断遇到主机端口、容器名称和卷的冲突。在构建这个工具之前,我尝试了一些组合,比如使用 -p 来命名项目/哈希工作树路径以获得唯一名称,管理带有端口变量的 .env 文件,以及使用 Caddy 进行反向代理,但我仍然在自动化方面遇到了一些问题,无法在不修改我的 Compose 文件或思考的情况下让所有内容协同工作。我还尝试了一些工具来解决这个问题,但最终要么是 Docker-in-Docker 设置,要么需要重写我的 Compose 文件。
Docktree 通过动态生成 Compose 覆盖文件来解决这些问题,而无需编辑你的 Compose 文件。它自动分配唯一的主机端口,隔离网络和命名卷,并重写显式的容器名称,以便同一堆栈的不同分支可以同时运行,而无需手动调整。对于某些支持“逻辑隔离”的服务,如 Postgres/MySQL,你还可以选择只使用一个数据库容器,并在其中运行多个隔离的数据库,而不是使用多个隔离的容器。
该命令行工具具有内置的反向代理,能够自动按主机名处理路由(通过 http://<worktree-name>.localhost 访问应用程序),并支持 Cloudflare/ngrok 共享隧道以将工作树暴露到外部。这些功能非常实用,因为我可以让代理端到端地处理某些事情,并返回一个我可以用来调查他们工作的链接,或者他们可以在结合像 Vercel 的代理浏览器时向我发送截图/演示。该工具还具有两个技能和 --json 输出,供你的代理自主驱动。不过,最终这些仍然是容器,因此现有的 Docker 工具和代理可以直接使用。
- 仓库: [https://github.com/Bnjoroge1/docktree](https://github.com/Bnjoroge1/docktree)
- 网站: [https://docktree.dev](https://docktree.dev)
查看原文
Hey folks.<p>While running multiple agents and git worktrees with a Docker Compose setup, I kept running into host port, container name, and volume collisions. Before building this tool, I tried some combinations of -p to namespace the projects/hash the worktree path for a unique name, managing .env files with port variables and Caddy for reverse-proxying, but I still had some issues getting everything to play together automatically without me making any changes to my compose files or thinking about it. I also tried a bunch of tools that try to address this but you end up with a Docker-in-docker setup, or they requires you to rewrite your compose files.<p>Docktree solves these issues by dynamically generating Compose overrides without editing your compose file. It auto-allocates unique host ports, isolates networks and named volumes, and rewrites explicit container names so different branches of the same stack run simultaneously without manual tweaks. There's also an option where, for certain services like postgres/mysql that support "logical isolation" you can have only one database container, and run multiple databases in them isolated instead of isolated containers.<p>The CLI features a built-in reverse proxy that handles routing by hostname automatically (accessing apps via http://<worktree-name>.localhost), Cloudflare/ngrok sharing tunnels to expose worktrees externally. These are pretty useful since I can just have agents work on something end to end and return me a link I can use to investigate their work or they can send me screenshots/walkthroughs when combined with something like Vercel's agent-browser. Tool also has two skills and --json outputs for your agents to autonomously drive them. These are still containers at the end of day though so the existing docker tools agents are familiar with work out of the box.<p>- Repository: <a href="https://github.com/Bnjoroge1/docktree" rel="nofollow">https://github.com/Bnjoroge1/docktree</a>
- Website: <a href="https://docktree.dev" rel="nofollow">https://docktree.dev</a>