1

The docker container stops upon completion of the script.

Running bash file ( docker-compose -f docker-compose.yml up -d ca.example.com orderer.example.com peer0.org1.example.com couchdb )

Get error:

Error response from daemon: Container 987d99518d4158f29f0800c8bbef1c2b1295d6fade341fde7c775e415b700a38 is not running

Running:

docker ps -a

Says status is exited(1) 13 seconds

So it ran and shut down?

Also each time I run:

docker rm -f $(docker ps -aq)

and rerun bash file its a different container that is in the error message.

Here is bash file:

#!/bin/bash
#
# SPDX-License-Identifier: Apache-2.0
# This code is based on code written by the Hyperledger Fabric community. 
# Original code can be found here: https://github.com/hyperledger/fabric-samples/blob/release/fabcar/startFabric.sh
#
# Exit on first error

set -e

# don't rewrite paths for Windows Git Bash users
export MSYS_NO_PATHCONV=1

starttime=$(date +%s)

if [ ! -d ~/.hfc-key-store/ ]; then
mkdir ~/.hfc-key-store/
fi

# launch network; create channel and join peer to channel
cd ../basic-network
./start.sh

# Now launch the CLI container in order to install, instantiate chaincode
# and prime the ledger with our 10 tuna catches
docker-compose -f ./docker-compose.yml up -d cli

docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode install -n tuna-app -v 1.0 -p github.com/tuna-app
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n tuna-app -v 1.0 -c '{"Args":[""]}' -P "OR ('Org1MSP.member','Org2MSP.member')"
sleep 10
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode invoke -o orderer.example.com:7050 -C mychannel -n tuna-app -c '{"function":"initLedger","Args":[""]}'

printf "\nTotal execution time : $(($(date +%s) - starttime)) secs ...\n\n"
printf "\nStart with the registerAdmin.js, then registerUser.js, then server.js\n\n"
hillodesign
  • 45
  • 1
  • 11

2 Answers2

1

remove that -d flag.

docker-compose -f ./docker-compose.yml up cli

only cli will exit as you don't need it to run in foreground but rest of your containers will always run in the foreground.

In case you wanna check deeper, in your docker-compose file, remove -d from command attribute.

Let me know if it works for you. and put here your docker ps -a in case it doesn't work for you.

Pandit
  • 748
  • 1
  • 7
  • 22
  • removed it from here as well for it to work: docker-compose -f docker-compose.yml up ca.example.com orderer.example.com peer0.org1.example.com couchdb – hillodesign Apr 05 '18 at 05:15
0

Solution 1 -

When you start your network with the following command, CLI container will stick around by default for 1000 seconds.

docker-compose -f docker-compose-cli.yaml up -d

so before running this command you will have to set the TIMEOUT variable. To Set the timeout execute the following command before starting your network.

export TIMEOUT=<no of seconds your CLI should stay up>

this way you can ensure your cli stays up as long as you need to execute further commands.

Also if your CLI is not running then simply execute this command to start the CLI.

docker start cli

Solution -2

Before running docker-compose -f docker-compose-cli.yaml up -d command open the docker-compose-cli.yaml` file.

then comment out the following line like this -

#command: /bin/bash -c './scripts/script.sh ${CHANNEL_NAME} ${DELAY}; sleep $TIMEOUT'

Hope this helps.

Anand Soni
  • 186
  • 1
  • 5