Answers: <p>the containers <code>hosts</code> file will differ from your hosts <code>hosts</code> file.</p>
  
  <p>see it kind of like a VM.</p>
  
  <p>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.</p>
  
  <p>So Problems:</p>
  
  <ul>
  <li><p>Your docker container knows nothing about the host <code>bitcoin</code>. an entry in your docker hosts <code>/etc/hosts</code> won't change that.</p></li>
  <li><p>Maybe your bitcoin service only binds to localhost <code>127.0.0.1</code> - 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.</p></li>
  <li><p>It would be easier if your bitcoind would also be a docker container and was configured inside the <code>docker-compose.yml</code>. That way you could resolve the host using the container name. But still your bitcoind should be configured to bind on every interface.</p></li>
  </ul>
  
  <p>Hope this helps ;)</p>
  
Answers: CC BY-SA 3.0
Answers: 2018-03-30T02:10:46.877Z
Answers: I added the bitcoin docker in the docker-compose.yml and it solved my problem. Thanks :-)
Answers: jfjobidon
Answers: CC BY-SA 3.0
Answers: 2018-03-29T14:36:02.650Z
Answers: 2018-03-29T14:36:02.650Z
Answers: Marvin Winkler
Body: <p>I have a micro-service <code>watchblockchain</code> that makes requests on <code>bitcoin</code> blockchain. When I use both services, everything works just fine.
  Then I want to put those services in docker containers.
  <code>watchblockchain</code> cannot communicate with the <code>bitcoin</code> docker.
  I use docker image: kylemanna/bitcoind/</p>
  
  <p>Here is my <code>bitcoin.conf</code> file:</p>
  
  <pre><code>disablewallet=1
  printtoconsole=1
  rpcauth=jfjobidon:123...xyz
  testnet=1
  txindex=1
  server=1
  rpcport=8332
  </code></pre>
  
  <p>I can open a console in the <code>bitcoin</code> container and verify that the blocks are downloading and I can make requests on the blockchain
  ex: bitcoin-cli getblockcount</p>
  
  <p>In <code>watchblockchain</code>, I have this connection config:</p>
  
  <pre><code>var clientBTC = new bitcoin.Client({
      host: 'bitcoin',
      port:  8332,
      user: 'jfjobidon',
      pass: 'Lw.....='
  });
  </code></pre>
  
  <p>And I mapped <code>bitcoin</code> to 127.0.0.1 in my hosts file</p>
  
  <p>My <code>docker-compose.yml</code>:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>When I launch: docker-compose up, I have the following error:</p>
  
  <blockquote>
    <p>Error: connect ECONNREFUSED 127.0.0.1:8332</p>
  </blockquote>
  
  <p>I think it is a network communication problem.</p>
  
  <p>How can I get my <code>watchblockchain</code> service to communication with the <code>bitcoin</code> docker ?</p>
  
Tags: <docker><docker-compose>
Title: docker micro-service cannot connect to bitcoin docker
UserDisplayName: jfjobidon
ThreadText: # docker micro-service cannot connect to bitcoin docker
  
  (Asked by: username_0 on 2018-03-29)
  
  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=username_0: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: 'username_0',
      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 ?
  
  **Tags:** docker, docker-compose
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-03-29. Score: 0 | Accepted answer
  
  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 ;)
  
  > **Comments:**
  > **username_0**: I added the bitcoin docker in the docker-compose.yml and it solved my problem. Thanks :-)  
  
  ---
  
  