book
book copied to clipboard
Document using anvil inside docker
A long running local anvil node is a great use-case for Docker. We should expand the tutorial to include this.
Can assign me :)
Hello!!! Just got here looking for docs on how to interact with Anvil within a docker container. I can run it properly like this (it's a public rpc being forked):
docker run -p 8545:8545 foundry "anvil --fork-url https://rpc.ankr.com/eth --fork-block-number 16596744"

But I can't get the cast command to work from outside the container:
cast call 0x6b175474e89094c44da98b954eedeac495271d0f "totalSupply()(uint256)" --rpc-url http://127.0.0.1:8545
error trying to connect: tcp connect error: Connection refused".
The cast request above works fine if I run anvil directly from my machine. I also tried running it without the rpc-url param.
I suspect this is related to the host server option we can pass with the anvil command, as if the node is rejecting requests coming from outside the container, but I'm not sure.
oh looks like the published docker version is out dated, this has since been fixed, notice how the server is listening on 127.0.0.1.
sorry about that
I'm publishing now, then you can set the host via anvil --host 0.0.0.0
creating an issue for auto mated docker releases... strange that we don't have this -.-
just opened https://github.com/foundry-rs/foundry/pull/4686
ah I tested this wrong, turns out this is already working by setting the --host param correctly:
docker run -p 8545:8545 ghcr.io/foundry-rs/foundry:latest "anvil --fork-url https://rpc.ankr.com/eth --fork-block-number 16596744 --host 0.0.0.0"
Fork
==================
Endpoint: https://rpc.ankr.com/eth
Block number: 16596744
Block hash: 0x9f8f2ae4b33ddf8d21db9456df6d495d5f212b01eb9abfa3192fcba2371014e7
Chain ID: 1
Listening on 0.0.0.0:8545
Thank you @mattsse that worked nicely, I really appreciate you taking the time to reply on a weekend, turns out I missed the host param.