1

使用 monero-javascript 托管 monero-wallet-rpc 的 Docker NodeJS 应用程序连接问题

我无法从我的 NodeJS Docker 容器连接到运行 monero-wallet-rpc 的本地主机。我不知道错误来自哪里。我看了几个小时。请帮忙。

在 dockerization 之前一切正常。

错误:

console.error(err);我的 Monero 连接文件中打印一个空数组:[]. 这证明 try 语句中存在错误。我想这与 docker 网络有关。但是,我可能是错的。

系统:

up to date Debian 10
Docker version 20.10.7, build f0df350
docker-compose version 1.29.2, build 5becea4c

码头工人撰写:

version: "3.8"
services:
  app:
    build: .
    env_file:
      - .env
    command: ["npm", "start"]
    restart: always
    ports:
      - 80:3000
    external_links:
      - mongo
    extra_hosts:
      - "host.docker.internal:host-gateway"

  mongo:
    image: mongo
    restart: always
    ports:
      - 27017:27017
    volumes:
      - ./mongodb/data:/data/db
    env_file:
      - .env

  mongo-seed:
    build: ./mongo-seed/.
    links:
      - mongo

volumes:
  db-data:
    name: mongodb

NodeJS Monero 连接(monero-javascript):

const monerojs = require("monero-javascript");

const moneroWalletRPCConnect = async () => {
  try {
    const moneroWalletRPC = await monerojs.connectToWalletRpc(
      process.env.MONERO_WALLET_RPC_URI,
      process.env.MONERO_WALLET_RPC_USER,
      process.env.MONERO_WALLET_RPC_PASSWORD
    );
    console.log(
      `MoneroWalletRPC connected to: ${process.env.MONERO_WALLET_RPC_URI}`
    );
    await moneroWalletRPC.openWallet(
      process.env.MONERO_WALLET_USER,
      process.env.MONERO_WALLET_PASSWORD
    );
    console.log(
      `MoneroWallet "${process.env.MONERO_WALLET_USER}" successfully opened.`
    );
    return await moneroWalletRPC;
  } catch (err) {
    console.error(err);
    process.exit(1);
  }
};

module.exports = moneroWalletRPCConnect;

.env 文件:

MONERO_WALLET_RPC_URI = "http://host.docker.internal:38083"
MONERO_WALLET_RPC_USER = "rpc_user"
MONERO_WALLET_RPC_PASSWORD = "abc123"
MONERO_WALLET_USER = "test"
MONERO_WALLET_PASSWORD = "123"

门罗币命令:

monerod --stagenet

monero-wallet-rpc --stagenet --daemon-address http://127.0.0.1:38081 --rpc-bind-port 38083 --rpc-login rpc_user:abc123 --wallet-dir .

在 nodejs 容器内:

root@45d96a2fc103:/usr/src/app# cat /etc/hosts 
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.1      host.docker.internal
172.18.0.2      45d96a2fc103
root@45d96a2fc103:/usr/src/app# getent hosts host.docker.internal
172.17.0.1      host.docker.internal
4

0 回答 0