I am trying to connect Ethers.js to a local Ehereum node (Geth) running in a Docker container. On the client side, I'm creating the provider this way: new ethers.providers.JsonRpcProvider('http://geth:8545')
. geth
is the node container hostname and both containers are on the same network: I can ping the Geth node from within the client container. When I start requesting the node from the client, I get a "noNetwork"
error.
When I run the client without Docker, requesting the node container through http://localhost:8545
, it is working properly.
What's wrong?
- Docker-compose file for the Geth node:
version: "3.5"
services:
geth:
container_name: geth
image: ethereum/client-go:latest
volumes:
- /etc/geth:/root/.ethereum:rw
ports:
- "8545:8545"
- "30303:30303"
networks:
- ethereum
entrypoint: "geth --nousb --http --http.corsdomain '*' --http.addr 0.0.0.0 --http.api personal,eth,net,web3 --syncmode light"
networks:
ethereum:
name: ethereum-net
- Docker-compose file for the client:
version: "3.5"
services:
eth-server:
container_name: eth_server_dev
build: packages/eth-server/.
environment:
- NODE_ENV=development
- NODE_PORT=3002
volumes:
- ./packages/eth-server/log:/app/log:rw
ports:
- "3002:3000"
networks:
- ethereum
networks:
ethereum:
external:
name: ethereum-net
- Error:
/app/node_modules/@ethersproject/logger/lib/index.js:179
var error = new Error(message);
^
Error: could not detect network (event="noNetwork", code=NETWORK_ERROR, version=providers/5.0.17)
at Logger.makeError (/app/node_modules/@ethersproject/logger/lib/index.js:179:21)
at Logger.throwError (/app/node_modules/@ethersproject/logger/lib/index.js:188:20)
at JsonRpcProvider.<anonymous> (/app/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:407:54)
at step (/app/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:46:23)
at Object.throw (/app/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:27:53)
at rejected (/app/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:19:65)
at processTicksAndRejections (node:internal/process/task_queues:93:5) {
reason: 'could not detect network',
code: 'NETWORK_ERROR',
event: 'noNetwork'
}