janoside / btc-rpc-explorer

Database-free, self-hosted Bitcoin explorer, via RPC to Bitcoin Core.
https://bitcoinexplorer.org
MIT License
1.48k stars 1.11k forks source link

not able to connect to bitcoind rpc from docker container #609

Open trieska opened 5 months ago

trieska commented 5 months ago

I am running archlinux on server and several services in docker and also native bitcoind. I am not able to install native btc-rpc-explorer arch package because known issue with node 21 and zeromq.

so lets try docker for btc-rpc-explorer, I did following steps: git close ... git checkout v3.4.0 docker buildx build -t btc-rpc-explorer:3.4.0 .

here is my compose

version: '3'

services:
  btc-rpc-explorer:
    image: btc-rpc-explorer:3.4.0
    container_name: btc-rpc-explorer
    user: 1000:984 # local user and docker group
    environment:
      - BTCEXP_BASEURL=/
      - BTCEXP_BITCOIND_HOST=192.168.75.10 # ip of server from local network 
      - BTCEXP_BITCOIND_PORT=8332
      - BTCEXP_BITCOIND_USER=__USER__
      - BTCEXP_BITCOIND_PASS=__PASS__
      - BTCEXP_BITCOIND_RPC_TIMEOUT=9000
      - BTCEXP_SLOW_DEVICE_MODE=true
      - BTCEXP_BASIC_AUTH_PASSWORD=__just__word__
      - BTCEXP_DISPLAY_CURRENCY=btc
      - BTCEXP_LOCAL_CURRENCY=eur
      - BTCEXP_UI_TIMEZONE=local
      - TZ=Europe/Brussel
    ports:
      - 3002:3002
    restart: unless-stopped

networks:
  default:
    name: all_containerrs # docker bridge network where all containers running
    external: true

here is part of bitcoind.conf:

rpcallowip=192.168.75.10/24
rpcallowip=127.0.0.1/8
rpcauth=__USER__:__hash_pass__ # this is tested and working
rpcbind=192.168.75.10
rpcbind=127.0.0.1

I did test rpc connection from laptop with curl and its pass and works ok

here is docker log from btc-rpc-explorer

> btc-rpc-explorer@3.4.0 start
> node ./bin/www

2024-01-10T09:13:17.220Z btcexp:app Searching for config files...
2024-01-10T09:13:17.225Z btcexp:app Config file not found at /home/node/.config/btc-rpc-explorer.env, continuing...
2024-01-10T09:13:17.225Z btcexp:app Config file not found at /etc/btc-rpc-explorer/.env, continuing...
2024-01-10T09:13:17.226Z btcexp:app Config file not found at /workspace/.env, continuing...
2024-01-10T09:13:17.226Z btcexp:app No config files found. Using all defaults.
2024-01-10T09:13:23.684Z btcexp:app Default cacheId '3.4.0'
2024-01-10T09:13:23.789Z btcexp:app Enabling view caching (performance will be improved but template edits will not be reflected)
2024-01-10T09:13:23.821Z btcexp:app Session config: {"secret":"*****","resave":false,"saveUninitialized":true,"cookie":{"secure":false}}
2024-01-10T09:13:23.847Z btcexp:app Environment(production) - Node: v16.20.2, Platform: linux, Versions: {"node":"16.20.2","v8":"9.4.146.26-node.26","uv":"1.43.0","zlib":"1.2.11","brotli":"1.0.9","ares":"1.19.1","modules":"93","nghttp2":"1.47.0","napi":"8","llhttp":"6.0.11","openssl":"1.1.1v+quic","cldr":"41.0","icu":"71.1","tz":"2022f","unicode":"14.0","ngtcp2":"0.8.1","nghttp3":"0.7.0"}
2024-01-10T09:13:23.929Z btcexp:error Error 3fehge9ee: Error: fatal: detected dubious ownership in repository at '/workspace'
To add an exception for this directory, call:

    git config --global --add safe.directory /workspace
, json: {"task":{"commands":["log","--pretty=format:òòòòòò %H ò %aI ò %s ò %D ò %b ò %aN ò %aE òò","-n 1"],"format":"utf-8"}}, userData: [object Object] (json: {"desc":"Error accessing git repo"})
2024-01-10T09:13:23.930Z btcexp:errorVerbose Stack: Error: fatal: detected dubious ownership in repository at '/workspace'
To add an exception for this directory, call:

    git config --global --add safe.directory /workspace

    at Object.action (/workspace/node_modules/simple-git/dist/cjs/index.js:1300:25)
    at PluginStore.exec (/workspace/node_modules/simple-git/dist/cjs/index.js:1335:29)
    at /workspace/node_modules/simple-git/dist/cjs/index.js:1731:43
    at new Promise (<anonymous>)
    at GitExecutorChain.handleTaskData (/workspace/node_modules/simple-git/dist/cjs/index.js:1729:16)
    at GitExecutorChain.<anonymous> (/workspace/node_modules/simple-git/dist/cjs/index.js:1713:44)
    at Generator.next (<anonymous>)
    at fulfilled (/workspace/node_modules/simple-git/dist/cjs/index.js:55:24)
2024-01-10T09:13:23.931Z btcexp:app Error getting sourcecode version, continuing to use default cacheId '3.4.0'
2024-01-10T09:13:23.931Z btcexp:app Starting BTC RPC Explorer, v3.4.0 (code: unknown commit) at http://127.0.0.1:3002/
2024-01-10T09:13:23.933Z btcexp:app RPC Credentials: {
    "host": "192.168.75.10",
    "port": "8332",
    "authType": "usernamePassword",
    "username": "__USER__",
    "password": "*****",
    "authCookieFilepath": "/home/node/.bitcoin/.cookie",
    "timeout": 9000
}
2024-01-10T09:13:23.933Z btcexp:app Connecting to RPC node at [192.168.75.10]:8332
2024-01-10T09:13:23.934Z btcexp:app RPC Connection properties: {
    "host": "192.168.75.10",
    "port": "8332",
    "username": "__USER__",
    "password": "*****",
    "timeout": 9000
}
2024-01-10T09:13:23.936Z btcexp:app Verifying RPC connection...
2024-01-10T09:13:23.939Z btcexp:app Loading mining pools config
2024-01-10T09:13:24.194Z btcexp:error Error RpcError-001: Error, json: {"code":403,"userData":{"request":"getnetworkinfo"}}, userData: [object Object] (json: {"request":"getnetworkinfo"})
2024-01-10T09:13:24.195Z btcexp:errorVerbose Stack: Error
    at IncomingMessage.<anonymous> (/workspace/node_modules/jayson/lib/client/http.js:78:23)
    at IncomingMessage.emit (node:events:525:35)
    at endReadableNT (node:internal/streams/readable:1358:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)
2024-01-10T09:13:24.197Z btcexp:error Error 32ugegdfsde: Error, json: {"code":403,"userData":{"request":"getnetworkinfo"}}, userData: [object Object] (json: {})
2024-01-10T09:13:24.197Z btcexp:errorVerbose Stack: Error
    at IncomingMessage.<anonymous> (/workspace/node_modules/jayson/lib/client/http.js:78:23)
    at IncomingMessage.emit (node:events:525:35)
    at endReadableNT (node:internal/streams/readable:1358:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)
2024-01-10T09:13:24.200Z btcexp:error Error RpcError-001: Error, json: {"code":403,"userData":{"request":"getblockchaininfo"}}, userData: [object Object] (json: {"request":"getblockchaininfo"})
2024-01-10T09:13:24.200Z btcexp:errorVerbose Stack: Error
    at IncomingMessage.<anonymous> (/workspace/node_modules/jayson/lib/client/http.js:78:23)
    at IncomingMessage.emit (node:events:525:35)
    at endReadableNT (node:internal/streams/readable:1358:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

thanks for help, tip ...

trieska commented 5 months ago

ok, I think that I find way how to do it. I did start container with network mode host, so container internal localhost is also host localhost.

here is my compose file

version: '3'

services:
  btc-rpc-explorer:
    image: btc-rpc-explorer:3.4.0
    container_name: btc-rpc-explorer
    user: 1000:984
    environment:
      - BTCEXP_BASEURL=/
      - BTCEXP_HOST=0.0.0.0
      - BTCEXP_BITCOIND_USER=username
      - BTCEXP_BITCOIND_PASS=pass_of_user
      - BTCEXP_BITCOIND_RPC_TIMEOUT=9000
      - BTCEXP_SLOW_DEVICE_MODE=true
      - BTCEXP_BASIC_AUTH_PASSWORD=just_a_word
      - BTCEXP_DISPLAY_CURRENCY=btc
      - BTCEXP_LOCAL_CURRENCY=eur
      - BTCEXP_UI_TIMEZONE=local
    restart: unless-stopped
    network_mode: host

and in bitcoin.conf I keep just this rpcauth=__USER__:__hash_pass__ # this is tested and working and did remove all other rpc related configs