When sending an RPC call to ganache I should get a valid response:
curl -X POST --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":67}' localhost:8545{"id":67,"jsonrpc":"2.0","result":"EthereumJS TestRPC/v2.1.5/ethereum-js"}curl -X POST --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":67}' localhost:8545 returns: curl: (52) Empty reply from server{"id":67,"jsonrpc":"2.0","result":"EthereumJS TestRPC/v2.1.5/ethereum-js"}docker run --rm -it -p 8545:8545 trufflesuite/ganache-cli:latestcurl -X POST --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":67}' localhost:8545I managed to get this working by running the following:
docker run -d -p 8545:8545 trufflesuite/ganache-cli:latest -h 0.0.0.0
For some reason having the ganache-cli server listening on host 0.0.0.0 instead of the loopback address 127.0.0.1 allowed me to connect. Could this be due to some networking changes in Docker?
Can confirm that @GarethOates's solution works
I'm experiencing the same issue, setting the default host of 0.0.0.0 did not help. Running docker on macOS, the port seems to be not exposed at all from the image
@fasmat Did you try the command as I wrote above? Have you tried disabling any local firewall's that might be blocking you from connecting to the container?
docker run -d -p 8545:8545 trufflesuite/ganache-cli:latest -h 0.0.0.0
@GarethOates
Yes thats the command i'm starting the container with. It's running in the background:
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
80a13b8964f9 trufflesuite/ganache-cli:latest "node ./build/cli.no…" 34 seconds ago Up 34 seconds 0.0.0.0:8545->8545/tcp trusting_ride
but no one is listening on 8545 according to lsof, no firewall is running.
Very strange! It works for myself and the CI build we run daily using those exact settings.
What is the configuration in your truffle.js file? Maybe there's something misconfigured there? It's specifying the correct port etc?
I think my issue is that I'm running my docker on macos and bridged networking doesn't seem to work here :-/
I'm running on MacOS as well and it's working. Did you do something manual to the dockervm to make it use bridged mode or is that the default? If it's default, then I assume mine is also in bridged mode.
I'm also running on MacOS and the workaround works for me. What happens when you invoke a shell inside the container and use the curl command in my original post?
@GarethOates @tim-hm
I investigated a little bit further this weekend, I had several issues that contributed to my problem:
Using the -h 0.0.0.0 flag allowed me to curl from one docker container to the container running ganache with success. Curl resolved ganache:8545 to docker_ganache_1.docker_default:8545. Using the full domain name I was also able to access ganache from within another docker container running a small test application (with the short domain name it did not work).
From my host machine I still cannot connect to ganache, neither with localhost:8545, 0.0.0.0:8545, ganache:8545 nor docker_ganache_1.docker_default:8545. Well at least when I'm connected to the wifi at my office, at my home wifi it did work ONCE with ganache:8545, but I cannot reproduce what I did different when it did work.
This seems like a docker / network configuration issue on my side and not directly related to the initial issue. But still thanks for helping :)
Hey everyone! I'm sorry for the delay on this one :(
A little background: per the discussion on https://github.com/trufflesuite/ganache-cli/pull/529, we decided to change the default to 127.0.0.1 as it is a minor security issue to let anyone on your network access your RPC port.
The reason this got messed up for Docker is because Docker acts as another computer on the network, which would mean you'd need to specify the specific ip address, or wildcard (0.0.0.0) for you to be able to bind to the port.
I apologize for the hindsight on this. I think it makes complete sense for the Docker instance to open the port completely (as this is just how you use Docker).
I will submit a fix that should auto use the -h 0.0.0.0 in the Docker file, but you seem to have figured out how to get it working in the meantime.
Closed via #559! This will go into the next release! Thanks everyone!
To add some more details:
After this fix you won't need to provide the -h 0.0.0.0 anymore. When the new Docker container is used, an environment variable is added to let ganache-cli know to change the default ip to 0.0.0.0 instead of 127.0.0.1.
We chose this implementation vs just adding the -h 0.0.0.0 to the arguments of the ENTRYPOINT in the Dockerfile so that you can still specify your own IP address if you have a usecase for that :man_shrugging:
And how to address -h 0.0.0.0 in the docker-compose file?
@abdennour I'm not sure I understand your question?
Thank you @seesemichaelj , I mean if we will convert docker run -d -p 8545:8545 trufflesuite/ganache-cli:latest -h 0.0.0.0 to docker-compose file, it will be:
services:
ganache-cli:
ports:
- '8545:8545'
image: 'trufflesuite/ganache-cli:latest'
I am asking how to add the -h 0.0.0.0 in that docker-compose file.
BTW, I read the comment closure and I see that now we don't need to use -h 0.0.0.0.
Hey @abdennour
I'm not super familiar with Docker compose, but an environment variable is what tells ganache-cli to set the default to 0.0.0.0. the below example will set it to 0.0.0.0 but not for other potential IPs.
I _believe_ this should work:
services:
ganache-cli:
ports:
- '8545:8545'
image: 'trufflesuite/ganache-cli:latest'
environment:
- DOCKER=true
This is mine, and it works perfectly
```version: '3'
services:
ganachecli:
image: trufflesuite/ganache-cli:latest
command: ganache-cli -h 0.0.0.0
ports:
- 8545:8545
So the need to explicitly specify -h 0.0.0.0 when running in a docker container is still present?
Its not anymore, old habit
@dumebi, it does not work for me.
@SalahAdDin can you open a new issue where we can discuss your issue? Please make sure to provide any relevant version information and reproduction steps, including the commands you're executing from which machine to try to connect
@seesemichaelj done!
Most helpful comment
@GarethOates @tim-hm
I investigated a little bit further this weekend, I had several issues that contributed to my problem:
Using the -h 0.0.0.0 flag allowed me to curl from one docker container to the container running ganache with success. Curl resolved ganache:8545 to docker_ganache_1.docker_default:8545. Using the full domain name I was also able to access ganache from within another docker container running a small test application (with the short domain name it did not work).
From my host machine I still cannot connect to ganache, neither with localhost:8545, 0.0.0.0:8545, ganache:8545 nor docker_ganache_1.docker_default:8545. Well at least when I'm connected to the wifi at my office, at my home wifi it did work ONCE with ganache:8545, but I cannot reproduce what I did different when it did work.
This seems like a docker / network configuration issue on my side and not directly related to the initial issue. But still thanks for helping :)