Docker Implementation Guide¶
Architecture Overview¶
Crucible uses Docker for fully containerized, reproducible experiment runs. The Docker setup has three tiers:
flowchart TD
subgraph Compose["docker-compose.yml"]
A["orchestrator<br>(experiment runs)<br><br>ENTRYPOINT:<br>uv run crucible"]
B["dashboard<br>(Streamlit UI)<br><br>ENTRYPOINT:<br>uv run streamlit"]
C["anvil-* (opt.)<br>(persistent chain daemons)<br><br>ENTRYPOINT:<br>anvil"]
A ~~~ B ~~~ C
end
Two Operational Modes¶
| Mode | Command | When to Use |
|---|---|---|
| Single-container (default) | docker compose run --rm --entrypoint bash orchestrator -c "fork && experiment run" |
Most experiments — Anvil runs inside the orchestrator container |
| Daemon + orchestrator | docker compose up -d anvil-ethereum && docker compose run orchestrator experiment run |
Multi-session workflows, streaming to dashboard |
Recommended: Single-container mode. It's simpler, fully isolated, and avoids the daemon Anvil's fork block mismatch problem.
Container Breakdown¶
Orchestrator Container¶
The orchestrator is the main workhorse. It contains:
- Crucible CLI — all commands (
fork,experiment run,diff, etc.) - Foundry (anvil, forge, cast) — for forking EVM chains
- Python 3.12 + dependencies — via uv package manager
# docker-compose.yml (simplified)
orchestrator:
build: .
entrypoint: ["uv", "run", "crucible"] # [warn] NOT a shell!
volumes:
- .:/workspace # project source (live-mounted)
- states_data:/workspace/states # persistent chain meta files
- logs_data:/workspace/logs # experiment logs & artifacts
- fork_cache:/workspace/.fork_cache # cached RPC data
env_file:
- .env # RPC URLs and configuration
Critical detail: The entire project directory is mounted as a bind volume (. → /workspace). This means:
- Code changes are live — no rebuild needed for Python changes
- But Foundry binaries are baked INTO the image — rebuild needed after Dockerfile changes
- Config files (testbed.yaml, .env) are live — no rebuild for config changes
Dashboard Container¶
The dashboard runs the Streamlit web UI for visualizing experiment results:
Daemon Anvil Containers (Optional)¶
The docker-compose.yml includes pre-configured Anvil containers for persistent chain forking:
anvil-ethereum— port 8545anvil-polygon— port 8546anvil-bsc— port 8547anvil-harmony— port 8548
These are optional — the single-container mode runs Anvil inside the orchestrator. However, if you want persistent chains that survive container restarts:
To use daemon containers, create a testbed.local.yaml pointing to Docker service names:
# testbed.local.yaml
chains:
ethereum:
host: "anvil-ethereum" # Docker service name
polygon:
host: "anvil-polygon"
Then run experiments against the persistent daemons:
Key Implementation Details¶
1. The --entrypoint bash Pattern¶
The orchestrator's Dockerfile defines:
This means docker compose run orchestrator <args> runs uv run crucible <args>. To run shell commands (like rm or chaining multiple crucible commands), you must override the entrypoint:
# [ok] CORRECT — override entrypoint to bash
docker compose run --rm --entrypoint bash orchestrator -c "
rm -f states/*.meta.json && \
uv run crucible fork --topology single && \
uv run crucible experiment run experiments/nomad_replay.yaml --no-baseline
"
# [fail] WRONG — this tries to run crucible sh -c "..."
docker compose run --rm orchestrator sh -c "..."
2. Stale Meta Files¶
The states_data Docker volume persists chain metadata (.meta.json files) across container runs. Each time crucible fork starts a chain, it writes a meta file like states/ethereum.meta.json. If you switch topologies (e.g., from poly_network to single), the old meta files for chains that no longer exist (e.g., bsc.meta.json) cause errors:
Solution: Always clean meta files before forking:
This is safe — meta files only track running Anvil processes. They're regenerated on the next fork.
3. Daemon Anvil Fork Block Mismatch¶
When using daemon Anvil containers (docker compose up -d anvil-ethereum), the fork block is set in docker-compose.yml via environment variables:
If testbed.yaml has a different fork_block for the same chain, the scenario runs against the daemon's block (e.g., 14,211,979) while the attack expects a different block (e.g., 15,259,100 for Nomad). This mismatch causes:
Solution: Use single-container mode (default) where crucible fork starts a fresh Anvil with the correct fork block from testbed.yaml. This avoids any configuration drift.
4. RPC URL Configuration¶
The daemon Anvil containers use ${ETH_RPC_URL} from the .env file:
But the single-container mode also uses testbed.yaml's rpc_url field:
Both modes read from .env. If the env var is unset, Anvil fails:
Solution: Verify environment variables before running:
5. Fork Block Management¶
testbed.yaml has a global fork_block per chain. Each experiment needs a different block:
| Attack | Ethereum Fork Block |
|---|---|
| Nomad Bridge | 15,259,100 |
| Wormhole Guardian | 14,125,553 |
| Poly Network | 12,996,693 |
These blocks differ. The safest approach is to use testbed.local.yaml for per-experiment overrides (this file is gitignored and deep-merged with testbed.yaml):
6. Volume Persistence¶
Three Docker volumes persist data across container runs:
| Volume | Mount | Contains | Cleanup Command |
|---|---|---|---|
states_data |
/workspace/states |
Anvil meta files (.meta.json) |
rm -f states/*.meta.json |
logs_data |
/workspace/logs |
Experiment run artifacts | crucible clean --logs-older-than 30 |
fork_cache |
/workspace/.fork_cache |
Cached RPC fork data | crucible cache clean --all |
To completely reset:
docker compose down -v # removes ALL volumes ([warn] deletes logs too)
docker compose build # rebuild images
Building¶
# Standard build
docker compose build
# Build without cache (if issues)
docker compose build --no-cache
# Build specific service
docker compose build orchestrator
The build:
1. Installs Python 3.12 + uv
2. Installs Foundry via foundryup --install nightly
3. Installs Python dependencies via uv sync
4. Copies source code
Note: The full project directory is mounted at runtime, so Python code changes don't need a rebuild. Only rebuild if Dockerfile, pyproject.toml, or uv.lock changes.
Running Experiments¶
Single Experiment¶
docker compose run --rm --entrypoint bash orchestrator -c "
rm -f states/*.meta.json && \
uv run crucible fork --topology single && \
uv run crucible experiment run experiments/nomad_replay.yaml --no-baseline
"
Determinism Check (Two Runs + Diff)¶
# Run 1
docker compose run --rm --entrypoint bash orchestrator -c "
rm -f states/*.meta.json && \
uv run crucible fork --topology single && \
uv run crucible experiment run experiments/nomad_replay.yaml --no-baseline
"
# Run 2
docker compose run --rm --entrypoint bash orchestrator -c "
rm -f states/*.meta.json && \
uv run crucible fork --topology single && \
uv run crucible experiment run experiments/nomad_replay.yaml --no-baseline
"
# Compare
docker compose run --rm orchestrator diff <run-a> <run-b>
Full Validation (All 3 Attacks)¶
# Nomad (fork block 15259100)
docker compose run --rm --entrypoint bash orchestrator -c "
rm -f states/*.meta.json && \
uv run crucible fork --topology single && \
uv run crucible experiment run experiments/nomad_replay.yaml --no-baseline
"
# Wormhole (fork block 14125553)
docker compose run --rm --entrypoint bash orchestrator -c "
rm -f states/*.meta.json && \
uv run crucible fork --topology single && \
uv run crucible experiment run experiments/wormhole_replay.yaml --no-baseline
"
# Poly Network (fork block 12996693)
docker compose run --rm --entrypoint bash orchestrator -c "
rm -f states/*.meta.json && \
uv run crucible fork --topology single && \
uv run crucible experiment run experiments/poly_network_replay.yaml --no-baseline
"
[warn] Remember: Update
testbed.local.yaml(ortestbed.yaml) with the correctfork_blockbefore each experiment.
Multi-Chain Topology (Requires Paid Archive RPCs)¶
# Requires BSC_RPC_URL and POLYGON_RPC_URL pointing to paid archive providers
docker compose run --rm --entrypoint bash orchestrator -c "
rm -f states/*.meta.json && \
uv run crucible fork --topology poly_network && \
uv run crucible experiment run experiments/poly_network_replay.yaml --no-baseline
"
Troubleshooting¶
sh -c Fails¶
$ docker compose run --rm orchestrator sh -c "..."
crucible: error: argument command: invalid choice: 'sh'
Cause: Entrypoint is crucible, not a shell. Fix: use --entrypoint bash.
Stale Meta File Errors¶
Cause: Volume-persisted .meta.json from a previous topology references a chain on a port that's not running. Fix: rm -f states/*.meta.json.
Chain Not Ready¶
Cause 1: Env var ${BSC_RPC_URL} is empty. Fix: set it in .env.
Cause 2: RPC provider doesn't support archive at the fork block. Fix: use a paid archive provider for old blocks.
Contract Has No Code¶
Cause: Wrong fork block or wrong contract address. Fix: update the fork block in testbed.yaml or verify the contract address on Etherscan.
Contract Address Is An EOA¶
Cause: Several attack packs had incorrect contract addresses that were actually EOAs. Fix: Always verify addresses on Etherscan before using them in attack packs.
Foundry Not Found¶
Inside Docker: Foundry should be pre-installed. Rebuild:
Locally: Install Foundry:
Comparison: Single-Container vs Daemon Approach¶
| Aspect | Single-Container (--entrypoint bash) |
Daemon (docker compose up -d) |
|---|---|---|
| Setup complexity | Minimal — one command | More complex — start daemons first |
| Fork block drift | None — fresh Anvil per run | Risk of mismatch with testbed.yaml |
| Chain persistence | No — Anvil dies with container | Yes — chains survive between runs |
| Isolation | Full — each run is clean | Shared state across runs |
| Docker Desktop visibility | Containers auto-delete (invisible) | Containers visible in Docker Desktop |
| When to use | Default — use this | Multi-session workflows only |