0

I have 2 docker images 1) for couchdb and 2) a web application. The web application couldnt able to talk to the couchdb which is running on the same machine.

When I access couchdb directly it is working http://127.0.0.1:5984/_utils/#database/ http://0.0.0.0:5984/_utils/#database/

What am I missing any pointers?

| Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:5984 [localhost/127.0.0.1] failed: Connection refused (Connection refused)
hashgraph_1  |  at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:159)
hashgraph_1  |  at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359)
hashgraph_1  |  at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381)
hashgraph_1  |  at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237)
hashgraph_1  |  at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
hashgraph_1  |  at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
hashgraph_1  |  at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
hashgraph_1  |  at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
hashgraph_1  |  at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
hashgraph_1  |  at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)

my docker compose file

version: "3"
services:
  hashgraph:
    build: "./"
    depends_on:
      - couchdb
    deploy:
      replicas: 1
      restart_policy:
        condition: always
    ports:
      - "51200-51299:51200-51299"
  couchdb:
    image: couchdb:2.1
    ports:
      - "5984:5984"
    deploy:
      replicas: 1
      restart_policy:
        condition: always

Output of docker ps

CONTAINER ID        IMAGE                            COMMAND                  CREATED              STATUS              PORTS                                                   NAMES
cc7e37cd6260        hashgraphexperiments_hashgraph   "java -jar swirlds.j…"   About a minute ago   Up About a minute   50200-50299/tcp, 0.0.0.0:51200-51299->51200-51299/tcp   hashgraphexperiments_hashgraph_1
9f4767b36aea        couchdb:2.1                      "tini -- /docker-ent…"   2 hours ago          Up About a minute   4369/tcp, 9100/tcp, 0.0.0.0:5984->5984/tcp              hashgraphexperiments_couchdb_1
5
  • you are trying to connect the couchdb running in port : 5984 of the host machine. have you mapped the webapplication port to this as well? Commented Mar 14, 2018 at 5:37
  • yes I did, In the web application my configuration to connect to couchdb is { "key": "protocol", "value": "http"}, { "key": "host", "value": "couchdb"}, Commented Mar 14, 2018 at 5:38
  • show the docker compose file or how you run it. Commented Mar 14, 2018 at 5:39
  • Do "docker ps" and show the state of both dockers Commented Mar 14, 2018 at 5:41
  • Hi, I added the docker ps output. still have the same issue Commented Mar 14, 2018 at 6:35

1 Answer 1

3

depends_on: it just wait to the other container to be started.

Whenever you want to call the couchdb from the hashgraph container code, you need to use couchdb:5984 instead of localhost:5984

Networking in Compose


You can also explicitly use the links entry instead of depends_on.

The description of links is

links: Link to containers in another service. Either specify both the service name and a link alias (SERVICE:ALIAS), or just the service name.

Links also express dependency between services in the same way as depends_on, so they determine the order of service startup.

version: "3"
services:
  hashgraph:
    build: .
    links:
      - couchdb:couchdb
    deploy:
      replicas: 1
      restart_policy:
        condition: always
    ports:
      - "51200-51299:51200-51299"
  couchdb:
    image: couchdb:2.1
    ports:
      - 5984:5984
    deploy:
      replicas: 1
      restart_policy:
        condition: always
Sign up to request clarification or add additional context in comments.

9 Comments

This doesn't work: couchdb:5984/_utils, I tried accessing with the browser. With localhost:5984/_utils I am seeing the couchdb page whereas with the other getting "couchdb’s server IP address could not be found."
This couchdb:5984/_utils is to call the couchdb FROM THE hashgraph container not from your local machine
can you post you docker ps console data?
@Minisha The localhost being used by the web application is that web app container. In that code, you need to connect to a remote server. Therefore, the links setup in compose. Though, the link is actually not needed, as pointed out here. docs.docker.com/compose/networking
Correct @cricket_007 You can always call other service by his service name
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.