简体   繁体   English

Hyperledger Composer无法与dockerized Node.js应用程序连接

[英]Hyperledger Composer cannot connect with dockerized Node.js app

I am working in a POC using Hyperledger Composer v0.16.0 and Node.js SDK. 我正在使用Hyperledger Composer v0.16.0和Node.js SDK在POC中工作。 I have deployed my Hyperledger Fabric instance following this developer tutorial and when I run locally my Node.js app via node server.js command it works correctly, I can retrieve participants, assets, etc. 我已按照此开发人员教程部署了我的Hyperledger Fabric实例,当我通过node server.js命令在本地运行我的Node.js应用程序时,它可以正常工作,我可以检索参与者,资产等。

However, when I Dockerize my Node.js app and I run the container for this app I am not able to reach the Hyperledger Fabric instance. 但是,当我Dockerize我的Node.js应用程序并运行此应用程序的容器时,我无法访问Hyperledger Fabric实例。 So, how can I set the credentials to be able to reach my Hyperledger Fabric or another one since my Node.js app? 那么,从我的Node.js应用程序开始,如何设置凭据以便能够访问我的Hyperledger Fabric或另一个?

My Dockerfile looks like this: 我的Dockerfile看起来像这样:

FROM node:8.9.1
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD [ "npm", "start" ]

I run my docker/node.js image with this command: 我用这个命令运行我的docker / node.js镜像:

docker run --network composer_default -p 3000:3000 -d myuser/node-web-app

There are 2 pitfalls to watch out for with Dockerizing your app. Docker化您的应用程序需要注意两个陷阱。 1. Location of Cards and 2. Network Address of Fabric servers. 1.卡的位置和2. Fabric服务器的网络地址。

  1. The Business Network Card(s) used by your app to connect to the Fabric. 您的应用用于连接到Fabric的业务网卡。 These cards are in a hidden folder under your default home folder eg /home/thatcher/.composer on a Linux machine. 这些卡位于默认主文件夹下的隐藏文件夹中,例如Linux机器上的/home/thatcher/.composer You need to 'pass' these into the container or share them with a shared volume as suggested by the previous answer. 您需要将这些“传递”到容器中,或者按照上一个答案的建议与共享卷共享它们。 So running your container for the first time try adding this in the command -v ~/.composer:/home/<user>/.composer where is the name of the default user in your container. 因此,首次运行容器尝试在命令-v ~/.composer:/home/<user>/.composer添加它,其中是容器中默认用户的名称。 Be aware also that the folder on your Docker Host machine must allow write access to the UID of the user inside the container. 还要注意Docker主机上的文件夹必须允许对容器内用户的UID进行写访问。

  2. When you have sorted out the sharing of the cards you need to consider what connection information is in the card. 当您整理出卡片共享时,您需要考虑卡片中的连接信息。 It is quite likely that the Business Network Card you are using will be using localhost as the addresses of your Fabric servers, the port forwarding of the ports from your Docker host into the containers means that localhost is easy and works. 您正在使用的业务网卡很可能使用localhost作为Fabric服务器的地址,从Docker主机到容器的端口转发意味着localhost很容易且有效。 However in your container localhost will redirect inside the container so will not see the Fabric. 但是在您的容器中,localhost将在容器内重定向,因此不会看到Fabric。 The arguments on the Docker command --network composer_default will set up your new container on the same Docker network as the Fabric Containers and so your Container could see the 'addresses' of the Fabric servers eg orderer.example.com but you card would then fail outside your container. Docker命令--network composer_default上的参数将在与Fabric Containers相同的Docker网络上设置您的新容器,因此您的Container可以看到Fabric服务器的“地址”,例如orderer.example.com但是您的卡将会在容器外面失败。 The best way forward would be to put the IP Address number of your Docker Host machine into the connection.json file instead of localhost, and then your card would work inside and outside of your container. 最好的方法是将Docker主机的IP地址编号放入connection.json文件而不是localhost,然后您的卡可以在容器内外工作。

So, credentials would be config info. 因此,凭据将是配置信息。 The two ways to pass config info into a basic docker container are: 将配置信息传递到基本docker容器的两种方法是:

  1. environment variables (-e) 环境变量(-e)
  2. mount a volumes (-v) with config info. 使用配置信息装入卷(-v)。

You can also have scripts that you install from Dockerfile that modify files and such. 您还可以使用从Dockerfile安装的脚本来修改文件等。

The docker logs may give clues as to the exact problem or set of problems. docker日志可以提供有关确切问题或问题集的线索。

docker logs mynode

You can also enter a running container and snoop around using the command 您还可以输入正在运行的容器并使用该命令窥探

docker exec -it mynode bash

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM