I ask this question again although a similar question is asked here. I answered that question with what I read and thought is the correct method but heck it doesn't work for me too.

Basically I run a geth instance in docker container and tried to connect geth console from my host computer.

The docker command is as follows: if [ $# -eq 0 ] then echo "No arguments supplied" else docker container run --network etherdev_net --rm --name etherdev_$1 -p 8545:8545 -v $gethdir/$1:/root/.ethereum -v $gethdir/$1/.ethash:/root/.ethash -v $bootnodedir:/root/bootnode etherdev fi

The docker container entry point basically invoke a shell script geth --networkid 5493 --bootnodes "$(echo -n 'enode://'; bootnode --writeaddress -nodekey /root/bootnode/nodekeyfile | tr -d '\n'; echo '@')" --mine --rpc --rpcport "8545" --port "30303" --rpccorsdomain "*" --nat "any" --rpcapi eth,web3,personal,net --etherbase 0 --unlock "$(cat /root/.ethereum/geth/security/coinbase)" --password /root/.ethereum/geth/security/password.sec

then I run this command on my host to attach a geth console but it returns an error message "Fatal: Failed to start the JavaScript console: api modules: Post http://localhost:8545: EOF"

geth attach http://localhost:8545

I had verified that I can connect to geth using the same command "geth attach http://localhost:8545" if I do a "docker container exec -it ... /bin/sh"

What is wrong here? Is the 8545 port published incorrectly?


When running outside docker container, it attaches like a remote system. And geth attach cannot connect to remote geth node using geth attach. This answer explains it better detail.

The solution to your problem can be an web3-console. You can use it as follows:

npm install -g @digix/web3-console

This will establish a web3 connection to localhost:8545 and provide you a console.

| improve this answer | |

It is because you use loopback interface when trying to connect. Just try to use:

docker run --rm -it ethereum/client-go \
attach http://$(ip route \
|grep "default via" \
|grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' \
|grep -m2 "" \
|tail -1):8545
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.