How to Run Crawl4AI in Docker at Scale
A thousand-page crawl in Crawl4AI runs fine on a laptop in one long process. Ten thousand pages does not, because headless browsers leak memory and one hung page stalls the queue. The fix is not a bigger script; it is the container and the queue discipline around it.
This is the layer most tutorials skip, and it is where crawls fail at week two.
What does the container setup need
The official image ships a headless browser and the library. Three changes to defaults matter:
- Memory limit on the container, set below host memory so the browser crashes the container rather than the host.
- Restart policy so a crashed container comes back on its own.
- A shared volume for output, so results survive a restart.
Without a memory limit, a leak takes down everything else on the box, and you find out from whoever owns the other services.
How do you make the crawl resumable
Write one file per URL or per batch, and keep a manifest of completed URLs. On restart, read the manifest and skip.
This is the single most valuable operational change. Crawls get interrupted; a resumable one costs minutes, a non-resumable one costs the whole run.
| Problem | Mitigation |
|---|---|
| Memory growth | Container limit plus periodic restart |
| Hung page | Per-page timeout |
| Restart loses work | Manifest plus per-batch output |
| One domain dominating | Per-domain concurrency cap |
| Duplicate fetches | URL normalization before queue |
Normalize URLs before the queue, not after. The same page with a tracking parameter and without is two pages to a crawler and one page to a reader.
How do you handle fairness across domains
Global concurrency is a blunt instrument. A ten-page domain and a two-thousand-page domain in the same queue means the small one finishes in seconds and the large one hogs workers for hours.
A simple fairness rule: cap in-flight requests per domain at one or two, and interleave the queue by domain. You finish the small site and keep the big one from saturating your outbound bandwidth.
What does it cost to run
Self-hosted, so the cost is compute: a small VM handles a few concurrent browser contexts, and additional memory buys more. Compare with a managed API priced per page; past roughly tens of thousands of pages a month, self-hosting is usually cheaper, and below that the managed service wins on maintenance time.
For extraction into structured rows rather than Markdown, a template-driven service like Browse AI avoids maintaining browsers entirely.
What breaks that you cannot fix
Sites that detect headless browsers and serve different content. Rotating proxies help and raise cost and complexity. Sites that require login need session handling, which is a different project.
Quick Summary
- Set a container memory limit and a restart policy before any large crawl.
- Keep a manifest of completed URLs to make the crawl resumable.
- Cap concurrency per domain and interleave the queue for fairness.
- Normalize URLs before queueing to avoid duplicate fetches.
- Self-hosting beats per-page pricing above roughly tens of thousands of pages monthly.
