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 '@192.168.2.2:30301')" --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?