Getting your CorDapps running in Docker

August 19, 2020

Image for post

Business networks using Corda

The dockerform gradle task

task prepareDockerNodes(type: net.corda.plugins.Dockerform, dependsOn: ['jar']) {dockerImage="corda/corda-zulu-java1.8-4.5:latest"nodeDefaults {
        projectCordapp {
            deploy = false
        }
        cordapp project(':contracts')
        cordapp project(':workflows')
    }node {
        name "O=Notary,L=London,C=GB"
        notary = [validating : false]
        p2pPort 10002
        rpcSettings {
            address("localhost:10003")
            adminAddress("localhost:10043")
        }
    }node {
        name "O=PartyA,L=London,C=GB"
        p2pPort 10002
        rpcSettings {
            address("localhost:10006")
            adminAddress("localhost:10046")
        }
        sshdPort 2223
        rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
    }node {
        name "O=PartyB,L=New York,C=US"
        p2pPort 10008
        rpcSettings {
            address("localhost:10009")
            adminAddress("localhost:10049")
        }
        sshdPort 2224
        rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
    }
}

Outlining your container cluster

dev@corda ~/D/s/B/yo-cordapp>master> ./gradlew prepareDockerNodes
Starting a Gradle Daemon (subsequent builds will be faster)> Task :deployNodesJava
Running DockerForm task
Deleting /Users/davidawad/Desktop/samples-java/Basic/yo-cordapp/build/nodes
Bootstrapping local test network in /Users/davidawad/Desktop/samples-java/Basic/yo-cordapp/build/nodes
Generating node directory for PartyA
Generating node directory for Notary
Generating node directory for PartyB
Waiting for all nodes to generate their node-info files...
Distributing all node-info files to all nodes
Loading existing network parameters... none found
Gathering notary identities
Generating contract implementations whitelist
New NetworkParameters {
      minimumPlatformVersion=7
      notaries=[NotaryInfo(identity=O=Notary, L=London, C=GB, validating=false)]
      maxMessageSize=10485760
      maxTransactionSize=524288000
      whitelistedContractImplementations {}
      eventHorizon=PT720H
      packageOwnership {}
      modifiedTime=2020-08-10T19:21:20.827Z
      epoch=1
  }
Bootstrapping complete!BUILD SUCCESSFUL in 43s
11 actionable tasks: 11 executed
dev@corda ~/D/s/B/yo-cordapp>master>cd build/nodes/
dev@corda ~/D/s/B/y/b/nodes>master>ls
Notary/             PartyA/             PartyB/             docker-compose.yml
dev@corda ~/D/s/B/y/b/nodes>master>cat docker-compose.yml
version: '3'
services:
  [ . . . ]  
  partyb:
    volumes:
    - /Users/davidawad/Desktop/samples-java/Basic/yo-cordapp/build/nodes/PartyB/node.conf:/etc/corda/node.conf
    [ . . . ]    environment:
    - ACCEPT_LICENSE=${ACCEPT_LICENSE}
    ports:
    - 10009
    - 2224
    image: corda/corda-zulu-java1.8-4.5:latest

Running the network

dev@corda ~/D/s/B/yo-cordapp>master>docker-compose -f ./build/nodes/docker-compose.yml up
WARNING: The ACCEPT_LICENSE variable is not set. Defaulting to a blank string.
Recreating nodes_partya_1 ...
Recreating nodes_notary_1 ...
Recreating nodes_partyb_1 ...
dev@corda ~/D/s/B/yo-cordapp>master>docker ps
CONTAINER ID        IMAGE                                 COMMAND             CREATED             STATUS              PORTS                                                                 NAMES
400636e89ddc        corda/corda-zulu-java1.8-4.5:latest   "run-corda"         36 seconds ago      Up 34 seconds       10200-10202/tcp, 0.0.0.0:32773->2223/tcp, 0.0.0.0:32772->10006/tcp    nodes_partya_1
dev@corda ~/D/s/B/y/b/nodes>master>ssh user1@0.0.0.0 -p 32773
The authenticity of host '[0.0.0.0]:32773 ([0.0.0.0]:32773)' can't be established.
RSA key fingerprint is SHA256:<you'll see a signature here>.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[0.0.0.0]:32773' (RSA) to the list of known hosts.
Password authentication
Password:Welcome to the Corda interactive shell.
You can see the available commands by typing 'help'.Mon Aug 10 20:21:50 GMT 2020>>> flow list
net.corda.core.flows.ContractUpgradeFlow$Authorise
net.corda.core.flows.ContractUpgradeFlow$Deauthorise
net.corda.core.flows.ContractUpgradeFlow$Initiate
net.corda.examples.yo.flows.YoFlowMon Aug 10 20:21:53 GMT 2020>>>
Mon Aug 10 20:24:54 GMT 2020>>> flow start YoFlow target: Partyb✓ Starting
 ✓ Creating a new Yo!
 ✓ Signing the Yo!
 ✓ Verifying the Yo!
 ✓ Sending the Yo!
          Requesting signature by notary service
              Requesting signature by Notary service
              Validating response from Notary service
     ✓ Broadcasting transaction to participants
▶︎ Done
Flow completed with result: SignedTransaction(id=A4050165C5795EEF852F94654091954FD8983C3641358BB724CE9D6D16A018B4)Mon Aug 10 20:25:08 GMT 2020>>>

Image for post

Docker containers “composed”