7

I installed two chaincode on a peer:

☁  basic-network [master] ⚡  ../../bin/peer chaincode list --installed
2018-06-25 10:37:44.825 CST [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2018-06-25 10:37:44.825 CST [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2018-06-25 10:37:44.825 CST [msp/identity] Sign -> DEBU 003 Sign: plaintext: 0A9C070A5C08031A0C08F8AAC1D90510...74616C6C6564636861696E636F646573
2018-06-25 10:37:44.825 CST [msp/identity] Sign -> DEBU 004 Sign: digest: 3F5F76846525A16930FC348CB24BC6D7C989EAF9D23E090D339C5D0B65E09D0E
Get installed chaincodes on peer:
Name: r_test_cc6, Version: 1.0, Path: chaincode_example02/go, Id: c7d2878644787e34a25b1e4e46703c7da301a830b68eba8e71ba7cadd2fbd480
Name: r_test_cc6, Version: 1.1, Path: github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02/go, Id: 42583a192be4d33bc2ddc85b3e061971667533019d431729bbac80f8844a00fe
2018-06-25 10:37:44.828 CST [main] main -> INFO 005 Exiting.....

I want to remove or delete the chaincode on a peer. How can I do this?

Lin Du
  • 88,126
  • 95
  • 281
  • 483

6 Answers6

12

To remove a chaincode on a peer you need to:

  • Kill the container that corresponds to the chaincode shim since a chaincode runs inside a docker container.

  • Delete the chaincode from the file system of the peer under /var/hyperledger/production/chaincodes

yacovm
  • 5,120
  • 1
  • 11
  • 21
  • thanks. what if I start a peer node in my local machine, not in docker container? – Lin Du Jun 25 '18 at 08:42
  • Is there any docs about chaincode always runs in a docker container? – Lin Du Jun 25 '18 at 09:02
  • yeah... I edited the answer and provided a link. From the link: "Chaincode is a program, written in Go, and eventually in other programming languages such as Java, that implements a prescribed interface. Chaincode runs in a secured Docker container " – yacovm Jun 25 '18 at 11:11
  • 1
    Do these actions remove the chaincode from channel configuration/current information? – Joaquim Oliveira May 13 '19 at 12:34
  • No, they don't. – yacovm May 13 '19 at 13:22
  • I have removed container which is running my chaincode, though it's showing in chaincodes list.. I have created multiple versions also for chaincode. all versions are showing on chaincode list. Please help me how can i remove completely. – Vijay Sep 11 '19 at 08:47
  • I have tried this but I try to reinstall the chaincode and I get: Error: could not assemble transaction, err proposal response was not successful, error code 500, msg chaincode with name 'mycc' already exists – icordoba Oct 09 '19 at 20:56
3

1) You can upgrade your chaincode and hit request to new chaincode.

adding to @yacovm 's answer -

2) You also need to delete docker image of the chaincode created :

docker images

docker rmi $(docker images chaincode_name -q)

If you want to remove multiple images as once ( assuming your chaincode image name starts with "cc_") try :

docker rmi $(docker images cc_* -q)

Hem M
  • 326
  • 2
  • 13
2

For Fabric 2.x

  1. Kill the chaincode container
  2. Delete the chaincode from the file system of the peer under /var/hyperledger/production/lifecycle/chaincodes
  3. Restart your peer container.

PS. After restarting the peer container all your chaincode containers will be restarted wait till all the containers are up.

Cm Jagtap
  • 147
  • 1
  • 2
  • 10
1

You can remove the image.

docker image list (find the image ID e.g. Image ID 3baa6abf8ac8)

docker image rm -f 3baa6abf8ac8

acc
  • 11
  • 1
1

The other way of deleting the docker images in Linux

  1. To delete all images

docker rmi -f $(docker images -a -q)

  1. To delete all containers including its volumes use,

docker rm -vf $(docker ps -a -q)

Note -f: This command force-removes a running container.

Remember, you should remove all the containers before removing all the images from which those containers were created.

NMSD
  • 484
  • 6
  • 18
0

Fabric 2.x - CCAAS

The following is applicable to CC deployed as external service (CCAAS).

  1. Spawn a shell on the peer(s) pod(or container). e.g. kubectl exec -it peer0-org1-some-alphanumerics sh -n the-namespace
  2. check your installed chaincodes: ls /var/hyperledger/production/lifecycle/chaincodes/.
  3. delete the cc you don't want: rm /var/hyperledger/production/lifecycle/chaincodes/someunwantedcc-with-alphanumerics.tat.gz
  4. restart the pod(container).

Note: There is also a copy of the cc tgz under the /var/hyperledger/production/externalbuilder/builds/ folder which doesn't seem to block the process.

Gr3at
  • 330
  • 6
  • 12