0

I have a micro-service watchblockchain that makes requests on bitcoin blockchain. When I use both services, everything works just fine. Then I want to put those services in docker containers. watchblockchain cannot communicate with the bitcoin docker. I use docker image: kylemanna/bitcoind/

Here is my bitcoin.conf file:

disablewallet=1
printtoconsole=1
rpcauth=jfjobidon:123...xyz
testnet=1
txindex=1
server=1
rpcport=8332

I can open a console in the bitcoin container and verify that the blocks are downloading and I can make requests on the blockchain ex: bitcoin-cli getblockcount

In watchblockchain, I have this connection config:

var clientBTC = new bitcoin.Client({
    host: 'bitcoin',
    port:  8332,
    user: 'jfjobidon',
    pass: 'Lw.....='
});

And I mapped bitcoin to 127.0.0.1 in my hosts file

My docker-compose.yml:

version: "3"
services:
  watchblockchain:
    build: ./watchBlockchain
    depends_on:
      - redis
    deploy:
      replicas: 1
      restart_policy:
        condition: on-failure
  redis:
    image: redis:4.0
    command: redis-server --appendonly yes
    ports:
      - "6379:6379"
    deploy:
      placement:
        constraints: [node.role == manager]
    command: redis-server --appendonly yes

When I launch: docker-compose up, I have the following error:

Error: connect ECONNREFUSED 127.0.0.1:8332

I think it is a network communication problem.

How can I get my watchblockchain service to communication with the bitcoin docker ?

1 Answer 1

0

the containers hosts file will differ from your hosts hosts file.

see it kind of like a VM.

Also 127.0.0.1 is the wrong address, you might need to configure the actual ip/hostname your host has and where the service is listening on inside the watchblockchain container.

So Problems:

  • Your docker container knows nothing about the host bitcoin. an entry in your docker hosts /etc/hosts won't change that.

  • Maybe your bitcoin service only binds to localhost 127.0.0.1 - this will also keep any docker container from connecting to it. Maybe you can configure it so that it binds to the docker bridge IP. So only all the docker containers are able to connect to it.

  • It would be easier if your bitcoind would also be a docker container and was configured inside the docker-compose.yml. That way you could resolve the host using the container name. But still your bitcoind should be configured to bind on every interface.

Hope this helps ;)

1
  • I added the bitcoin docker in the docker-compose.yml and it solved my problem. Thanks :-)
    – jfjobidon
    Mar 30, 2018 at 2:10

Your Answer

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

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