The Geth team conveniently provides a Docker container for the latest Geth builds, but when using Docker on Windows or Mac OS (where Docker is using a virtual machine to host containers) how to run it such that RPC calls can be seen on the local workstation? Running docker run -p 8545:8545 --name geth ethereum/cilent-go --rpc
doesn't seem to do it.
Testing with CURL:
curl -X POST -H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id":"curltest", "method": "web3_clientVersion", "params": [] }' \
"http://192.168.99.100:8545"
I get no response from the above command, it just spins until it times out.
Best Answer
The issue is that the default RPC server is "localhost", which doesn't seem to work properly in a Docker container in a VM. Instead, the server name of "0.0.0.0" will bind to all IP addresses the container is given, which will work with Docker's networking better.
So, the one-line command to run would be:
For better security, your 'go to' command to get Geth up-and-running should probably not have the
--rpc
flag on by default. Instead, try doing something like:That will open up the sharing port such that other Ethereum nodes can find it, but not start the RPC server right away. That
docker exec
command will get you into the Geth console, where you can then runadmin.startRPC('0.0.0.0', 8545)
. If you want access to the running logs of the Geth node, rundocker logs -f geth
.