Query CouchDB Container API Directly


How to query CouchDB Container API directly?

✍: FYIcenter.com


If you are running BYFN (Build Your First Network) with the CouchDB option, the World State of each peer node is stored a CouchDB server running as Docker container.

The CouchDB server supports a REST API interface at the local port 4369, which is mapped to another port of the hosting system.

You can use "curl" command to query the CouchDB REST API directly, if it has no user name and password protection.

1. List all CouchDB containers:

$ docker ps --all | grep couchdb

hyperledger/fabric-couchdb  4369/tcp, 9100/tcp,>5984/tcp  couchdb0
hyperledger/fabric-couchdb  4369/tcp, 9100/tcp,>5984/tcp  couchdb1
hyperledger/fabric-couchdb  4369/tcp, 9100/tcp,>5984/tcp  couchdb2
hyperledger/fabric-couchdb  4369/tcp, 9100/tcp,>5984/tcp  couchdb3

As you can see, 4 CouchDB API ports are mapped to 5984, 6984, 7984, and 8984 of the local hosting system.

2. Query couchdb0 container, which should be connected peer0.org1. After connecting to the 5984 port, you need to enter the "GET ..." command by 2 "Enter" keys.

$ curl http://localhost:5984/

 "vendor":{"name":"The Apache Software Foundation"}}

3. Get all databases on the server:

$ curl http://localhost:5984/_all_dbs


As you can see, there 3 databases for "mychannel" channel and 1 database for "mycc" chaincode running on "mychannel":

4. Get all documents from the "mychannel_mycc" database:

$ curl http://localhost:5984/mychannel_mycc/_all_docs


5. Get the content of document "a":

$ curl http://localhost:5984/mychannel_mycc/a

    "_id": "a",
    "_rev": "2-f5911b70345a8fe9b45e699f2aebb2b8",
    "~version": "\u0000CgMBBAA=",
    "_attachments": {
        "valueBytes": {
            "content_type": "application\/octet-stream",
            "revpos": 2,
            "digest": "md5-qpvq4\/JGMCgu7WtvFu5zbg==",
            "length": 2,
            "stub": true


CouchDB Server Admin Web Portal

Peer and CouchDB Container Dependency

Hyperledger Fabric Docker Containers

⇑⇑ Hyperledger Tutorials

2020-06-08, 1501🔥, 0💬