Customize chaincode docker image


Kimheng SOK
 

Dear all,

Each time we instantiate or upgrade the chaincode, there is a new chaincode docker image and container exist.

If we want to customize the default chaincode image to install some other applications, so that when we instantiate the chaincode we have all the environment we want, how can we do it? Where does the chaincode dockerfile located?

Bests,


Gari Singh <garis@...>
 

Each type of chaincode (Go, Java, Node) has it's own Dockerfile but the contents of each Dockerfile are actually embedded within the peer binary itself. So unless you want to modify the peer itself, you cannot currently modify the contents of the Dockerfile(s). In the upcoming 2.0 release, you will have the ability to build your own chaincode launcher and then you can build/deploy chaincode in any manner you desire.

In the meantime, you can actually modify the contents of both the image used to build chaincode and the image used to run chaincode.

Building:

In v1.4.x, Go and Node chaincode are built using the fabric-ccenv image (you can find the Dockerfile under images/ccenv in the Fabric source tree). If you need any extra libraries for building, you can build your own image based on fabric-ccenv. Note that for Go we only take the binary chaincode which is built and use it in the actual chaincode container. For Node it's similar ... we take the contents of the installed Node app (including node_modules). You can specify your own chaincode builder by setting the "chaincode.builder" property in your peer's config file to the name of your custom image. Note that Java actually uses the "chaincode.java.runtime" image for building (fabric-javaenv found in the fabric-chaincode-java repository).

In 2.0, Node uses the fabric-nodeenv (found in the fabric-chaincode-node repository) image rather than fabric-ccenv.


Running:

In 1.4.x, the fabric-ccenv image will build the chaincode binary / Node app which will then be used to build the actual chaincode image. It basically just copies the contents into the runtime images which are specified by the "chaincode.golang.runtime", "chaincode.java.runtime", "chaincode.node.runtime" properties in the config file. So if for example your Go chaincode uses external shared libraries, you could add them to the appropriate base runtime image. For Go, this is the fabric-baseos image. For Node it is fabric-baseimage.

In 2.0, Node uses fabric-nodeenv for runtime as well.


-- Gari

-----------------------------------------
Gari Singh
Distinguished Engineer, CTO - IBM Blockchain
IBM Middleware
550 King St
Littleton, MA 01460
Cell: 978-846-7499
garis@...
-----------------------------------------

-----fabric@... wrote: -----
To: fabric@...
From: "Kimheng SOK"
Sent by: fabric@...
Date: 09/18/2019 03:28AM
Subject: [EXTERNAL] [Hyperledger Fabric] Customize chaincode docker image

Dear all,

Each time we instantiate or upgrade the chaincode, there is a new chaincode docker image and container exist.

If we want to customize the default chaincode image to install some other applications, so that when we instantiate the chaincode we have all the environment we want, how can we do it? Where does the chaincode dockerfile located?

Bests,


Kimheng SOK
 

Hi,

Thank for your detail explanation, I will discover it more.

Bests,

On Wed, Sep 18, 2019 at 3:48 PM Gari Singh <garis@...> wrote:
Each type of chaincode (Go, Java, Node) has it's own Dockerfile but the contents of each Dockerfile are actually embedded within the peer binary itself.  So unless you want to modify the peer itself, you cannot currently modify the contents of the Dockerfile(s).  In the upcoming 2.0 release, you will have the ability to build your own chaincode launcher and then you can build/deploy chaincode in any manner you desire.

In the meantime, you can actually modify the contents of both the image used to build chaincode and the image used to run chaincode.

Building:

In v1.4.x, Go and Node chaincode are built using the fabric-ccenv image (you can find the Dockerfile under images/ccenv in the Fabric source tree).  If you need any extra libraries for building, you can build your own image based on fabric-ccenv.  Note that for Go we only take the binary chaincode which is built and use it in the actual chaincode container.  For Node it's similar ... we take the contents of the installed Node app (including node_modules).  You can specify your own chaincode builder by setting the "chaincode.builder" property in your peer's config file to the name of your custom image.  Note that Java actually uses the "chaincode.java.runtime" image for building (fabric-javaenv found in the fabric-chaincode-java repository).

In 2.0, Node uses the fabric-nodeenv (found in the fabric-chaincode-node repository) image rather than fabric-ccenv.


Running:

In 1.4.x, the fabric-ccenv image will build the chaincode binary / Node app which will then be used to build the actual chaincode image.  It basically just copies the contents into the runtime images which are specified by the "chaincode.golang.runtime", "chaincode.java.runtime", "chaincode.node.runtime" properties in the config file.  So if for example your Go chaincode uses external shared libraries, you could add them to the appropriate base runtime image.  For Go, this is the fabric-baseos image.  For Node it is fabric-baseimage.

In 2.0, Node uses fabric-nodeenv for runtime as well.


-- Gari

-----------------------------------------
Gari Singh
Distinguished Engineer, CTO - IBM Blockchain
IBM Middleware
550 King St
Littleton, MA 01460
Cell: 978-846-7499
garis@...
-----------------------------------------

-----fabric@... wrote: -----
To: fabric@...
From: "Kimheng SOK"
Sent by: fabric@...
Date: 09/18/2019 03:28AM
Subject: [EXTERNAL] [Hyperledger Fabric] Customize chaincode docker image

Dear all,

Each time we instantiate or upgrade the chaincode, there is a new chaincode docker image and container exist.

If we want to customize the default chaincode image to install some other applications, so that when we instantiate the chaincode we have all the environment we want, how can we do it? Where does the chaincode dockerfile located?

Bests, 


sanjaykumar3989@...
 

Hi,

I have created the customized image from hyperledger/fabric-javaenv:amd64-1.4.4. and used as CORE_CHAINCODE_JAVA_RUNTIME=sanjaykumar3989/myenv:amd64-1.4.4.

In this new image i am replacing build.sh and start file in location  /root/chaincode-java/. 
The build.sh is running successfully as my jar is building but after that it exit with below msg:
Error: could not assemble transaction, err proposal response was not successful, error code 500, msg chaincode registration failed: container exited with 1


Matthew White
 

Hello - my best guess would be that the chaincode is failing to call back to the peer to 'register'. 
 
Usually capturing the docker logs of the chaincode really helps in cases like this. 
 
Can I ask what your requirement is to customize the docker image? Just curious!
 
 
Regards, Matthew.
Matthew B White  IBM Blockchain Solutions Architect
 
Email me at WHITEMAT@...
Find me on StackOverflow, and generally at  calanais.me.uk
 
Note: restricted availability for meetings 14:30 to 17:00 UK Tuesday 
IBM United Kingdom Limited, Hursley Park, Winchester, Hampshire, SO21 2JN

"The wrong answers are the ones you go looking for when the right answers stare you in the face"
 
 
 
----- Original message -----
From: sanjaykumar3989@...
Sent by: fabric@...
To: fabric@...
Cc:
Subject: [EXTERNAL] Re: [Hyperledger Fabric] Customize chaincode docker image
Date: Thu, Jan 30, 2020 5:46 AM
 
Hi,

I have created the customized image from hyperledger/fabric-javaenv:amd64-1.4.4. and used as CORE_CHAINCODE_JAVA_RUNTIME=sanjaykumar3989/myenv:amd64-1.4.4.

In this new image i am replacing build.sh and start file in location  /root/chaincode-java/. 
The build.sh is running successfully as my jar is building but after that it exit with below msg:
Error: could not assemble transaction, err proposal response was not successful, error code 500, msg chaincode registration failed: container exited with 1
 
Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 741598.
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU


sanjaykumar3989@...
 

Hi,

Every time when i initiate the chaincode , it take time to build the jar. To skip this process for multiple times and to learn the flow of hyperledger CC flow, i am customizing the image.

Usually capturing the docker logs of the chaincode really helps in cases like this. - CC container get killed automatically. Is there is some way how i can capture the logs?


Brett T Logan <brett.t.logan@...>
 

Part of the chaincode instantiation process is to compile the JAR, this isn't something you can hijack in 1.4.x without modifying the source code. Fabric v2.0 (which released last week) provides a framework for configuring and running chaincode however you want: https://hyperledger-fabric.readthedocs.io/en/master/cc_launcher.html
 
And, if you want to debug your chaincode containers you can forward their standard output to the peer container where you can grep the log for the chaincodes output. You can enable this by setting CORE_VM_DOCKER_ATTACHSTDOUT=true in your peer launch environment, but note, this is not meant for production purposes as it can leak sensitive information into the peer logs from broken or malicious code.
 
Brett Logan
Software Engineer, IBM Blockchain
Phone: 1-984-242-6890
 
 
 

----- Original message -----
From: sanjaykumar3989@...
Sent by: fabric@...
To: fabric@...
Cc:
Subject: [EXTERNAL] Re: [Hyperledger Fabric] Customize chaincode docker image
Date: Mon, Feb 3, 2020 6:47 PM
 
Hi,

Every time when i initiate the chaincode , it take time to build the jar. To skip this process for multiple times and to learn the flow of hyperledger CC flow, i am customizing the image.

Usually capturing the docker logs of the chaincode really helps in cases like this. - CC container get killed automatically. Is there is some way how i can capture the logs?
 


sanjaykumar3989@...
 

How peer run the chain code container ? I want to expose port from chaincode container and map with host machine. 

I want to customized the docker run cmd fired from peer node.