7

I just reinstalled Fabric Samples v2.2.0 from Hyperledger Fabric repository according to the documentation.

But when I try to run asset-transfer-basic application located in fabric-samples/asset-transfer-basic/application-javascript directory by running node app.js the wallet is created and an admin and user is registered. But then it tries to invoke the function as given in app.js and shows this error

error: [Transaction]: Error: No valid responses from any peers. Errors:
    peer=peer0.org1.example.com:7051, status=500, message=error in simulation: failed to execute transaction 
aa705c10403cb65cecbd360c13337d03aac97a8f233a466975773586fe1086f6: could not launch chaincode basic_1.0:b359a077730d7
f44d6a437ad49d1da951f6a01c6d1eed4f85b8b1f5a08617fe7: error starting container: error starting container:
 API error (404): network _test not found

Response of a transaction to invoke a function

This error never occured before. But somehow after reinstalling docker and Hyperledger Fabric fabric-samples it never seems to find the network _test.

N.B. : Before reinstalling name of the network was net_test. But now when I try docker network ls it shows a network called docker_test. I am using Windows Subsystem for Linux (WSL) version 1.

NETWORK ID     NAME          DRIVER    SCOPE
b7ac05456f46   bridge        bridge    local
acaa5856b871   docker_test   bridge    local
866f58b9078d   host          host      local
4812f94efb15   none          null      local

How can I fix the issue occurring when I try to run the application?

sayhan
  • 95
  • 2
  • 7

5 Answers5

10

In my opinion, the CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE setting seems to be wrong.
you can check docker-compose.yaml or core.yaml

1. docker-compose.yaml

  • I will explain fabric-samples/test-network as targeting according to your current situation.
  • You can check in CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE in docker-compose.yaml
  • Perhaps in your case(fabric-samples/test-network), the value of ${COMPOSE_PROJECT_NAME} was not set properly, so it was set to _test.
  • Make sure the value is set correctly and change it to your network name.
# hyperledger/fabric-samples/test-network/docker/docker-compose-test-net.yaml
# based v2.2
...
  peer0.org1.example.com:
    container_name: peer0.org1.example.com
    image: hyperledger/fabric-peer:2.2
    environment:
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      # - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=${COMPOSE_PROJECT_NAME}_test
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=docker_test
...

2. core.yaml

If you have not set the value in the docker-compose.yaml peer, you need to check the core.yaml referenced by the peer.

you can find the networkMode parameter in core.yaml

# core.yaml
...
vm:
    docker:
        hostConfig:
            # NetworkMode: host
            NetworkMode: docker_test
...

If neither is set, it will be set to the default value. However, as you see _test being logged, the wrong value have been set in one of the two section, and you need to correct the value to the value you intended.

myeongkil kim
  • 2,465
  • 4
  • 16
  • 22
  • I changed the value of `CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE` variable in my `docker-compose-test-net.yaml` file from `${COMPOSE_PROJECT_NAME}_test` to `docker_test` and the application was able to find the `docker_test` network. I changed both the files. But later when I redo the change in `core.yaml` the application still worked. – sayhan Jan 29 '21 at 08:36
  • `core.yaml` is the value set when the initial peer bootstrap, and if an environment variable is set, it will be overwritten with the environment variable. In other words, if both are set, they are set to the env value of `docker-compose.yaml`. I'm so glad your problem was solved. – myeongkil kim Jan 29 '21 at 10:05
  • It was very helpful to know about these files. Is there any resource/documentation which can be helpful to understand the contents of the `.yaml` files which comes with `fabric-samples`? – sayhan Jan 29 '21 at 12:24
  • I don't know if it will help. In my case, I understood it by comparing the code with the content introduced in the official document. – myeongkil kim Jan 30 '21 at 04:34
3

This issue is related to docker networking. In complete to @nezuko-response.

Create a file and name it ".env" in the same directory where your docker-compose file exists.
Add the following line in it:

COMPOSE_PROJECT_NAME=net

Use docker-compose up to update the container with the new configurations.

Or bring the HL network down (./network.sh down) and up (./network.sh up), restarting the test-nework.

Otherwise you'll still get the same error even after creating ".env" file.

More explanation about docker networking

comocoder
  • 84
  • 6
2

run ./network down then

export COMPOSE_PROJECT_NAME=net

afterwards

./network start
Badr Bellaj
  • 11,560
  • 2
  • 43
  • 44
0

I copied this from someone .This one worked for me !!

Please create a file named ".env" in the same directory where your docker-compose file exists. Add the following line in ".env" file:-

COMPOSE_PROJECT_NAME=net
0

This worked for me

export COMPOSE_PROJECT_NAME=net
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 28 '21 at 22:20