Hyperledger Composer Rest Server对接Cloudant DB的COMPOSER_DATASOURCES配置咨询
Got it, let's walk through exactly how to configure the COMPOSER_DATASOURCES environment variable to get your Hyperledger Composer Rest Server storing cards in IBM Cloudant NoSQL DB. I’ve broken this down into straightforward steps:
COMPOSER_DATASOURCES structure This variable uses a JSON object to define the database connector and its connection details. For Cloudant, you’ll need to specify the cloudant connector type, along with your Cloudant instance’s connection credentials and target database name.
First, grab these values from your IBM Cloud Cloudant service:
- Cloudant Service URL: Found in your Cloudant instance’s "Credentials" tab (looks like
https://<your-instance-id>.cloudantnosqldb.appdomain.cloud) - IAM API Key: If you’re using IBM IAM authentication (the default for newer Cloudant instances), generate this in the Cloudant credentials or IBM IAM console. It needs permissions to write to your target database.
- Target Database Name: Create a new database in the Cloudant UI first (e.g.,
composer-cards— the rest server won’t auto-create this for you).
If you’re using legacy Cloudant authentication (username/password), you’ll instead need:
- Cloudant username and password (from your legacy credentials)
- The full authenticated URL (format:
https://<username>:<password>@<instance-id>.cloudantnosqldb.appdomain.cloud)
COMPOSER_DATASOURCES JSON Use one of these templates based on your authentication method:
For IAM Authentication (Recommended)
{ "db": { "name": "db", "connector": "cloudant", "url": "https://<your-instance-id>.cloudantnosqldb.appdomain.cloud", "database": "<your-db-name>", "iamApiKey": "<your-iam-api-key>", "iamUrl": "https://iam.cloud.ibm.com/identity/token" } }
For Legacy Username/Password Authentication
{ "db": { "name": "db", "connector": "cloudant", "url": "https://<your-username>:<your-password>@<your-instance-id>.cloudantnosqldb.appdomain.cloud", "database": "<your-db-name>" } }
How you set this depends on your operating system or deployment method:
Linux/macOS Terminal
export COMPOSER_DATASOURCES='{"db": {"name": "db", "connector": "cloudant", "url": "https://...", "database": "composer-cards", "iamApiKey": "your-key-here"}}'
Windows Command Prompt
set COMPOSER_DATASOURCES={"db": {"name": "db", "connector": "cloudant", "url": "https://...", "database": "composer-cards", "iamApiKey": "your-key-here"}}
Docker Deployment
Include the variable when running the rest server container:
docker run -e COMPOSER_DATASOURCES='{"db": {...}}' hyperledger/composer-rest-server -c <your-admin-card> -n never -w true
Start your Composer Rest Server, then:
- Check your Cloudant database — you should see new documents of type
Cardwhen you import or create a card via the REST API. - Test creating a card through the REST interface, then confirm it appears in the Cloudant database.
Quick Notes
- Double-check that your IAM API Key has Writer access to the Cloudant database (you can set this in IBM Cloud’s IAM policies).
- If you run into SSL issues (unlikely for IBM Cloud-hosted Cloudant), add
"ssl": trueto thedbobject in your JSON config.
内容的提问来源于stack exchange,提问作者MrL

