Following the steps will help to access service discovery from client application.
1.
Before Running network (peer) add the CORE_PEER_GOSSIP_EXTERNALENDPOINT information to the peer service of docker-compose.yml file. It will be helpful if we set at least one anchor peer to each organization.
services:
peer1.org1.example.com:
environment:
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org1.example.com:5051
# Need to change the peer domain and port with your desired value
- CORE_PEER_GOSSIP_USELEADERELECTION=true
- CORE_PEER_GOSSIP_ORGLEADER=false
External endpoint will help peers from other organizations to find the peer.
2.
Update the peer information from networkConnection.yml file with discover: true which is used to connect the application with the network.
channels:
testchannel:
peers:
peer1.org1.example.com:
endorsingPeer: true
chaincodeQuery: true
ledgerQuery: true
eventSource: true
discover: true
3.
Enable discovery during gateway creation from application
Gateway.Builder builder = Gateway.createBuilder();
...
builder.discovery(true).identity(wallet, userName).networkConfig(connectionProfile);
// Connect to gateway using application specified parameters
gateway = builder.connect();
After running the application it will use discovery service from peer1.org1.example.com peer and will get other organization peers information (e.g peer2.org2.example.com, peer1.org2.example.com) from the channel.
Hope it will solve your problem.
But it will not run with the domains (peer1.org1.example.com, peer1.org2.example.com, peer2.org2.example.com) as the domains has no bind with actual IP.
You need to add the route in your /etc/hosts file to test the application (Update 127.0.0.1 with your desired IP).
127.0.0.1 peer1.org1.example.com
127.0.0.1 peer1.org2.example.com
127.0.0.1 peer2.org2.example.com
Run the client application again and check if it works properly.