You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何构建嵌入已有BNA的Hyperledger Composer Playground Docker镜像?

Solutions to Package BNA into Hyperledger Composer Playground with Embedded Network

Awesome question! I’ve worked with Hyperledger Composer Playground and embedded networks before, so let’s walk through two solid, actionable solutions to get your demo up and running without relying on a real Fabric network:

Solution 1: Precreate Embedded Connection Cards & Copy to the Image

Your initial idea is spot-on—copying preconfigured embedded cards into the container’s card directory works perfectly, as long as those cards use the embedded connection type. Here’s how to execute it:

Step 1: Generate Embedded Cards Locally

First, install the Hyperledger Composer CLI to create the required cards:

npm install -g composer-cli

Then follow these steps:

  1. Package your Business Network into a BNA file (if you haven’t already):
    composer archive create -t dir -n ./path-to-your-bna-source
    
  2. Create a simple embedded connection profile file (save as embedded-connection.json):
    {
      "name": "embedded",
      "type": "embedded"
    }
    
  3. Deploy the BNA to an embedded network and generate admin cards:
    # Import the default PeerAdmin embedded card (included with Composer CLI)
    composer card import -f ~/.composer/cards/PeerAdmin@embedded.card || echo "PeerAdmin card already exists"
    
    # Install the BNA to the embedded network
    composer network install --card PeerAdmin@embedded --archiveFile your-network-name.bna
    
    # Start the network and create an admin identity
    composer network start --networkName your-network-name --networkVersion 1.0.0 --card PeerAdmin@embedded --networkAdmin admin --networkAdminEnrollSecret adminpw
    
    # Create and import the admin card for your network
    composer card create -p embedded-connection.json -u admin -n your-network-name -s adminpw
    composer card import -f admin@your-network-name.card
    

Step 2: Build the Custom Docker Image

Create a Dockerfile that copies these precreated cards into the playground image:

FROM hyperledger/composer-playground:latest

# Copy your pregenerated cards into the container's composer card directory
COPY ./admin@your-network-name.card /home/composer/.composer/cards/
COPY ./PeerAdmin@embedded.card /home/composer/.composer/cards/

# Ensure the composer user owns the cards directory (avoids permission issues)
RUN chown -R composer:composer /home/composer/.composer/cards

Build and run the image as usual—when you launch Playground, your embedded network will be ready to use immediately.

Solution 2: Auto-Deploy BNA via Startup Script (No Precreated Cards)

If you want to avoid pregenerating cards locally, you can automate the BNA deployment directly in the container at startup using a custom script. This keeps your workflow entirely within Docker:

Step 1: Create a Startup Script

Save this as start-playground.sh (replace placeholders with your BNA details):

#!/bin/bash
set -e

# Create an embedded connection profile
cat > /tmp/embedded-connection.json << EOF
{
  "name": "embedded",
  "type": "embedded"
}
EOF

# Ensure the default PeerAdmin embedded card is available
composer card import -f /home/composer/.composer/cards/PeerAdmin@embedded.card || true

# Install and start the BNA
composer network install --card PeerAdmin@embedded --archiveFile /app/your-network-name.bna
composer network start --networkName your-network-name --networkVersion 1.0.0 --card PeerAdmin@embedded --networkAdmin admin --networkAdminEnrollSecret adminpw

# Create and import the admin card for your network
composer card create -p /tmp/embedded-connection.json -u admin -n your-network-name -s adminpw
composer card import -f admin@your-network-name.card

# Launch the playground service
exec composer-playground

Step 2: Write the Dockerfile

FROM hyperledger/composer-playground:latest

# Copy your BNA file into the container
COPY ./your-network-name.bna /app/

# Copy and make the startup script executable
COPY ./start-playground.sh /app/
RUN chmod +x /app/start-playground.sh

# Switch to the composer user (required for proper permissions)
USER composer

# Override the default entrypoint to run our script
ENTRYPOINT ["/app/start-playground.sh"]

When you run this container, the script will automatically deploy your BNA to an embedded network and set up the necessary cards before launching Playground.

Key Things to Keep in Mind

  • Version Matching: Make sure your BNA’s Hyperledger Composer version matches the version of the hyperledger/composer-playground image (use a specific tag like 0.20.9 instead of latest for stability).
  • Embedded Network Limits: This is a single-node, in-memory network—great for demos, but never use it for production.
  • Permissions: Always ensure the /home/composer/.composer/cards directory is owned by the composer user in the container to avoid access errors.

内容的提问来源于stack exchange,提问作者jpietzsch

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:35:40