1

I run private geth testnet and my program is on docker. Everytime I try to call api I get: no JSON RCP response. Must I run geth on docker too?

1
  • Your program doesnt have an access to host OS. Commented Jan 30, 2018 at 7:14

2 Answers 2

1

Something you could try is a docker-compose with your app and a build-in geth docker image.

For example

docker-compose.yml

version: '3'
services:
  geth:
    image: kunstmaan/ethereum-geth-testnet
    ports:
      - "8545:8545"
      - "30303:30303"
    stdin_open: true
    tty: true

  your_app:
    build: ./
    ports:
      - "8080:8080"
    (...)

Build the image

$ docker-compose -f docker-compose.yml build

Run it

$ docker-compose -f docker-compose.yml up
4
  • my docker-compose.yml:
    – Agniezhk
    Commented Jan 30, 2018 at 10:23
  • are you trying to connect to http://localhost:8545 ? Commented Jan 30, 2018 at 10:38
  • yes, localhost:8545
    – Agniezhk
    Commented Jan 30, 2018 at 11:44
  • in Dockerfile, do you expose 8545: EXPOSE 8545 Commented Jan 30, 2018 at 13:43
1

I ran into the same problem. I had a web server running in a Docker Container and an Ethereum node (for testnet) running on my machine. It seemed the app in Docker wont be able to connect to the node outside of it. Here is how I solved that issue without having to run Geth node inside my container:

  1. Make sure you have --rpc and --rpccorsdomain flags when starting Geth
  2. In your Application running inside Docker, make sure to point your web3 provider to your machine correctly https://docs.docker.com/docker-for-mac/networking/ for my machine i had to use: "docker.for.mac.localhost".

web3 = new Web3(new Web3.providers.HttpProvider("http://docker.for.mac.localhost:8545"));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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