firecrawl的docker安装和api调用
记录下FireCrawl Docker部署,以及aip调用以备忘。
一、部署前准备
1. 环境要求
- 硬件:2核CPU、4GB内存、50GB硬盘
- 软件:
- Windows:Docker Desktop(需启用WSL2)
- Linux:Docker + Git(Ubuntu推荐版本24.04)
- 网络:需外网访问(国内用户建议科学上网或使用镜像源)
二、部署步骤
1. 克隆代码仓库
bash
git clone https://github.com/mendableai/firecrawl.git cd firecrawl
如果github登录不了,可以使用gitee下载
git clone https://gitee.com/JonDO/firecrawl.git
2. 配置环境变量
- 复制示例文件:
cp apps/api/.env.example .env
3. Docker配置与启动
Ubuntu系统
- 安装Docker:
# 添加GPG密钥与仓库 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg echo "deb [arch= $ (dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $ (lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null sudo apt update && sudo apt install docker-ce docker-ce-cli containerd.io
- 解决镜像下载问题:
修改/etc/docker/daemon.json
添加镜像源(如华为云):
重启Docker服务:{ "registry-mirrors": ["https://docker.1ms.run"] }
bashsudo systemctl restart docker
- 构建与运行:
docker-compose build --no-cache # 强制重新构建 docker-compose up -d
4. 验证部署
- 检查服务状态:
docker-compose ps # 查看容器运行状态
- API测试:
curl -X GET http://localhost:3002/test # 返回"Hello, world!"表示成功
- 管理界面:
浏览器访问http://localhost:3002/admin/@/queues
查看任务队列。
三、api调用
有两种调用方式,一种是返回task_id,一种是直接返回结果。
1、返回task_id
String url = "http://192.168.1.1:3002/v1/crawl"
可以在浏览器访问 http://localhost:3002/admin/@/queues
查看任务队列。
2、直接返回结果
String url = "http://192.168.1.1:3002/v0/scrape"
调用的参考代码如下:
// var url = "http://192.168.1.1:3002/v0/scrape"
var url = "http://192.168.1.1:3002/v1/crawl"Map headers = {"Content-Type": "application/json"
}
Map requestBody = {"url": "" //爬取网址// "option": {// "maxDepth": 3, //下转几层// "limit": 1, //最多爬取几页,包括base page// // "scrapeOptions": {// // "formats": ["markdown","html"]// // }// // "keepCookies": true,// // "headers": {// // "Cookie": str// // }// }
}
var ret = http.connect(url).header(headers).body(requestBody).post().getBody()return ret