Need Help Setting Up Hyperledger Fabric?
Get expert guidance on deploying and managing your Hyperledger Fabric network.
Complete Guide
Quick Answer
Setting up Hyperledger Fabric requires: prerequisites (Docker, Docker Compose, Fabric binaries), defining network structure, generating crypto material, creating channel artifacts, starting the network, creating and joining channels, and deploying chaincode. The most common deployment mistake is not testing certificate expiry rotation before going to production — certificates expire after 1 year and rotation requires careful coordination.
Prerequisites
# Install Docker (required for Fabric containers)
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# Install Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/download/v2.20.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
# Install Fabric binaries
curl -sSL https://bit.ly/2ysbOFE | bash -s -- 2.5.0 1.5.7
export PATH=$PATH:$(pwd)/fabric-samples/binStep 1: Define Your Network Structure
Before running any commands, document your network:
How many organizations?
What is each org's MSP ID?
Which org runs the ordering service?
What channels will exist?
What chaincode will run on each channel?
Step 2: Generate Crypto Material
# cryptogen: generates TLS certs and signing keys for all network components
cat > crypto-config.yaml << 'EOF'
OrdererOrgs:
- Name: Orderer
Domain: example.com
Specs:
- Hostname: orderer
PeerOrgs:
- Name: Org1
Domain: org1.example.com
EnableNodeOUs: true
Template:
Count: 2 # 2 peer nodes for Org1
Users:
Count: 1 # 1 additional user besides admin
- Name: Org2
Domain: org2.example.com
EnableNodeOUs: true
Template:
Count: 2
Users:
Count: 1
EOF
cryptogen generate --config=./crypto-config.yamlStep 3: Create Channel Artifacts
# configtx.yaml: defines organizations, policies, and genesis block
# Create channel transaction
configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/mychannel.tx -channelID mychannel
# Create genesis block for the ordering service
configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.blockStep 4: Start the Network
# docker-compose.yaml defines all network containers
docker-compose -f docker/docker-compose-test-net.yaml up -d
# Check all containers are running
docker ps
# Expected: peer0.org1.example.com, peer0.org2.example.com, orderer.example.comStep 5: Create and Join Channel
# Create channel (only once)
peer channel create -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/mychannel.tx --tls --cafile $ORDERER_CA
# Join Org1 peer to channel
peer channel join -b mychannel.block
# Switch to Org2 and join
export CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
export CORE_PEER_ADDRESS=peer0.org2.example.com:9051
peer channel join -b mychannel.blockStep 6: Deploy Chaincode
# Fabric 2.x lifecycle: package → install → approve → commit
# Package
peer lifecycle chaincode package mycc.tar.gz --path ./chaincode/mycc --lang golang --label mycc_1.0
# Install on each org's peers
peer lifecycle chaincode install mycc.tar.gz
# Approve for Org1
peer lifecycle chaincode approveformyorg -o orderer.example.com:7050 --channelID mychannel --name mycc --version 1.0 --sequence 1 --tls --cafile $ORDERER_CA
# Approve for Org2 (same command, different env vars)
peer lifecycle chaincode approveformyorg ...
# Commit chaincode (after all required orgs have approved)
peer lifecycle chaincode commit -o orderer.example.com:7050 --channelID mychannel --name mycc --version 1.0 --sequence 1 --tls --cafile $ORDERER_CA --peerAddresses peer0.org1.example.com:7051 --peerAddresses peer0.org2.example.com:9051Step 7: Test With Invoke and Query
# Invoke chaincode function (state-changing)
peer chaincode invoke -o orderer.example.com:7050 --channelID mychannel --name mycc -c '{"function":"createAsset","Args":["asset1","blue","5","Tomoko","300"]}' --tls --cafile $ORDERER_CA
# Query chaincode (read-only)
peer chaincode query -C mychannel -n mycc -c '{"Args":["ReadAsset","asset1"]}'