Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hyperledger Fabric with docker not storing data after restart

I setup Hyperledger Fabric V0.6 with docker image. I wrote small chain code program and perform some operations. Data is getting stored and fetched on request from Hyperledger blockchain.

I restart my chaincode program and data still persist. Ofcouse this should be expected behaviour.

But when I stop my Hyperledger fabric with command docker-compose down and start it again with docker-compose start and then start my chaincode program, I found that the whole data which was written before restart is gone. I couldn't find any data in my blockchain.

How can I avoid this behaviour of Hyperledger? I am running it on single peer/node. With multiple peers, if one of the peer restarted, then data/transactions from other peers get copied on it. But consider a worst scenario when all peers down. Does that mean we loose all our data?

like image 505
NGR Avatar asked Apr 10 '17 18:04

NGR


2 Answers

As per the official docs docker-compose down stops and removes all containers listed in docker-compose file along with their volumes (unless specified as external, have a look into the documentation).

You may want to stop the containers with docker-compose stop - this way after docker-compose up their data will be preserved.

like image 158
marszczybrew Avatar answered Sep 22 '22 14:09

marszczybrew


A Note on Data Persistence

If data persistence is desired on the peer container or the CouchDB container, one option is to mount a directory in the docker-host into a relevant directory in the container. For example, you may add the following two lines in the peer container specification in the docker-compose-base.yaml file:

volumes: - /var/hyperledger/peer0:/var/hyperledger/production

For the CouchDB container, you may add the following two lines in the CouchDB container specification:

volumes: - /var/hyperledger/couchdb0:/opt/couchdb/data

like image 22
lissdy Avatar answered Sep 18 '22 14:09

lissdy