展示 HN:为您的代理运行多个 Docker Compose 实例

2 分•作者: Bnjoroge•3 个月前
大家好。 在使用 Docker Compose 设置运行多个代理和 Git 工作区时,我经常遇到主机端口、容器名称和卷冲突的问题。在开发这个工具之前,我尝试了使用 `-p` 来为项目命名空间化/哈希工作区路径以生成唯一名称,通过管理包含端口变量的 `.env` 文件以及使用 Caddy 进行反向代理,但仍然遇到一些问题,无法在不修改 Compose 文件或进行思考的情况下让所有东西自动协同工作。我还尝试了许多试图解决此问题的工具,但最终会得到一个 Docker-in-Docker 设置,或者需要重写你的 Compose 文件。 Docktree 通过动态生成 Compose 覆盖文件来解决这些问题,无需编辑你的 Compose 文件。它会自动分配唯一的主机端口,隔离网络和命名卷,并重写显式的容器名称,以便同一堆栈的不同分支可以同时运行而无需手动调整。还有一个选项,对于像 PostgreSQL/MySQL 这样支持“逻辑隔离”的服务,你可以只有一个数据库容器,并在其中运行多个隔离的数据库,而不是使用隔离的容器。 该 CLI 包含一个内置的反向代理,可以自动处理按主机名的路由(通过 `http://<worktree-name>.localhost` 访问应用程序),以及 Cloudflare/ngrok 共享隧道,用于将工作区暴露到外部。这些功能非常有用,因为我可以让代理端到端地处理某项任务并返回一个我可以用来调查其工作的链接,或者在与 Vercel 的代理浏览器等工具结合使用时,它们可以向我发送截图/操作指南。该工具还具有两个技能和 `--json` 输出,供代理自主驱动。但归根结底,它们仍然是容器,因此现有的 Docker 工具和代理可以开箱即用地使用。 - 仓库:https://github.com/Bnjoroge1/docktree - 网站: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&#x2F;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&#x27;s also an option where, for certain services like postgres&#x2F;mysql that support &quot;logical isolation&quot; 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:&#x2F;&#x2F;&lt;worktree-name&gt;.localhost), Cloudflare&#x2F;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&#x2F;walkthroughs when combined with something like Vercel&#x27;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:&#x2F;&#x2F;github.com&#x2F;Bnjoroge1&#x2F;docktree" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Bnjoroge1&#x2F;docktree</a> - Website: <a href="https:&#x2F;&#x2F;docktree.dev" rel="nofollow">https:&#x2F;&#x2F;docktree.dev</a>