Skip to content

Commit a7b34ce

Browse files
authored
Merge pull request #15 from AgentFlocks/docs/docker-browser-configuration
docs: add Docker browser configuration guide
2 parents cd1d765 + b5f3505 commit a7b34ce

3 files changed

Lines changed: 126 additions & 0 deletions

File tree

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# 3.8 Docker 浏览器配置
2+
3+
在 macOS 或 Windows 上使用 Docker 部署 Flocks 时,可以让容器中的 Flocks 连接宿主机上的 Google Chrome。Chrome 负责提供 CDP(Chrome DevTools Protocol)服务,Flocks 通过该服务控制浏览器。
4+
5+
## 3.8.1 macOS 宿主机启动 Chrome
6+
7+
在 macOS 宿主机执行:
8+
9+
```bash
10+
open -na "Google Chrome" --args \
11+
--remote-debugging-port=19122 \
12+
--remote-debugging-address=0.0.0.0 \
13+
--user-data-dir="$HOME/.flocks/browser/chrome-debug"
14+
```
15+
16+
该命令会使用独立的用户数据目录启动 Chrome,避免与日常使用的 Chrome 实例冲突。
17+
18+
执行以下命令验证 CDP 服务:
19+
20+
```bash
21+
curl http://127.0.0.1:19122/json/version
22+
```
23+
24+
如果返回的 JSON 中包含 `webSocketDebuggerUrl`,表示 Chrome 已启动成功。
25+
26+
## 3.8.2 Windows 宿主机启动 Chrome
27+
28+
在 Windows PowerShell 中执行:
29+
30+
```powershell
31+
$chrome = "$env:ProgramFiles\Google\Chrome\Application\chrome.exe"
32+
Start-Process -FilePath $chrome -ArgumentList @(
33+
"--remote-debugging-port=19122",
34+
"--remote-debugging-address=0.0.0.0",
35+
"--user-data-dir=$env:USERPROFILE\.flocks\browser\chrome-debug"
36+
)
37+
```
38+
39+
如果 Chrome 未安装在默认路径,请将 `$chrome` 修改为实际的 `chrome.exe` 路径。该命令同样使用独立的用户数据目录,不会复用日常 Chrome 实例的配置。
40+
41+
执行以下命令验证 CDP 服务:
42+
43+
```powershell
44+
curl.exe http://127.0.0.1:19122/json/version
45+
```
46+
47+
如果返回的 JSON 中包含 `webSocketDebuggerUrl`,表示 Chrome 已启动成功。Windows 防火墙还需要允许 Docker Desktop 的虚拟网络访问宿主机 `19122` 端口。
48+
49+
## 3.8.3 启动 Flocks 容器
50+
51+
启动容器时映射 Flocks 的 WebUI 和后端 API 端口:
52+
53+
macOS:
54+
55+
```bash
56+
docker run -d \
57+
--name flocks \
58+
-e TZ=Asia/Shanghai \
59+
-e BU_CDP_URL="http://host.docker.internal:19122" \
60+
-p 8000:8000 \
61+
-p 5173:5173 \
62+
--shm-size 4gb \
63+
-v "${HOME}/.flocks:/home/flocks/.flocks" \
64+
ghcr.io/agentflocks/flocks:latest
65+
```
66+
67+
Windows PowerShell:
68+
69+
```powershell
70+
docker run -d `
71+
--name flocks `
72+
-e TZ=Asia/Shanghai `
73+
-e BU_CDP_URL="http://host.docker.internal:19122" `
74+
-p 8000:8000 `
75+
-p 5173:5173 `
76+
--shm-size 4gb `
77+
-v "${env:USERPROFILE}\.flocks:/home/flocks/.flocks" `
78+
ghcr.io/agentflocks/flocks:latest
79+
```
80+
81+
`BU_CDP_URL` 会随容器启动注入,使 Flocks 可以直接连接宿主机的 Chrome。Chrome 运行在宿主机上,容器主动连接宿主机的 `19122` 端口,因此不需要使用 `-p 19122:19122` 将该端口发布到宿主机。
82+
83+
## 3.8.4 在 Flocks 中配置浏览器
84+
85+
进入 Flocks 容器:
86+
87+
```bash
88+
docker exec -it flocks bash
89+
```
90+
91+
首次配置时,在容器中执行:
92+
93+
不要通过 `FLOCKS_ROOT=/tmp/.flocks` 重定向整个 Flocks 数据目录。这样会同时影响 config、plugins、memory 和 console 登录态,容器重建后这些数据都会丢失。推荐只将 `~/.flocks/browser` 链接到临时目录,其他数据仍保留在持久化挂载的 `~/.flocks` 中。
94+
95+
macOS Docker Desktop:
96+
97+
```bash
98+
mv ~/.flocks/browser /tmp/flocks-browser
99+
ln -s /tmp/flocks-browser ~/.flocks/browser
100+
export BU_CDP_URL="http://host.docker.internal:19122"
101+
flocks browser --setup
102+
```
103+
104+
Windows Docker Desktop:
105+
106+
```bash
107+
mv ~/.flocks/browser /tmp/flocks-browser
108+
ln -s /tmp/flocks-browser ~/.flocks/browser
109+
export BU_CDP_URL="http://host.docker.internal:19122"
110+
flocks browser --setup
111+
```
112+
113+
`host.docker.internal` 是 Docker Desktop 提供的宿主机域名,用于从 macOS 或 Windows 容器访问宿主机服务,无需在文档或配置中写入具体 IP 地址。
114+
115+
symlink 会保存在持久化的 `~/.flocks` 目录中,只把浏览器运行目录重定向到 `/tmp/flocks-browser`,不会改变其他 Flocks 数据的位置。完成配置后,Flocks 会通过 `BU_CDP_URL` 连接宿主机上的 Chrome。
116+
117+
如果删除并重新创建了容器,symlink 仍保存在持久化目录中,但临时目录会被清空。进入新容器后执行以下命令恢复浏览器运行目录:
118+
119+
```bash
120+
mkdir -p /tmp/flocks-browser
121+
flocks browser --setup
122+
```
123+
124+
请勿将 `19122` 端口暴露到不受信任的网络,避免其他设备通过 CDP 控制浏览器。

‎docs/md/communication.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
- [3.5 文件与配置](/md/communication-files-config)
1010
- [3.6 网络访问清单](/md/communication-network-access)
1111
- [3.7 Flocks 安全管控](/md/communication-security-controls)
12+
- [3.8 Docker 浏览器配置](/md/communication-docker-browser)
1213

1314
如果你同时需要先看整体再逐条阅读,也建议先按上面顺序依次打开。

‎src/.vitepress/config.mts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export default defineConfig({
7474
{ text: '3.5 文件与配置', link: '/md/communication-files-config' },
7575
{ text: '3.6 网络访问清单', link: '/md/communication-network-access' },
7676
{ text: '3.7 Flocks 安全管控', link: '/md/communication-security-controls' },
77+
{ text: '3.8 Docker 浏览器配置', link: '/md/communication-docker-browser' },
7778
],
7879
},
7980
{

0 commit comments

Comments
 (0)