0

I'm trying to run bitcoind in a docker container backed by Windows 10/WSL2 using Docker Desktop. I'm using the ruimarinho/bitcoin-core:0.20.1-alpine image defined here: https://github.com/ruimarinho/docker-bitcoin-core.

I have a simple compose file as follows so I can run it with just docker-compose up bitcoind:

version: "3.8"
services:
    bitcoind:
        image: ruimarinho/bitcoin-core:0.20.1-alpine
        command:
            -listen
            -server
            -printtoconsole
            -chain=regtest
            -rpcbind=0.0.0.0:18443
            -rpcallowip=0.0.0.0/0
            -rpcauth={nonsense}
        ports:
            - "18443:18443"
            - "18444:18444"

When I run the compose command as shown above, the container starts and appears to run as intended:

The log:

λ docker-compose run bitcoind
Creating bitcoin_bitcoind_run ... done
/entrypoint.sh: assuming arguments for bitcoind
/entrypoint.sh: setting data directory to /home/bitcoin/.bitcoin

2020-10-03T19:26:47Z Bitcoin Core version v0.20.1.0-g7ff64311bee570874c4f0dfa18f518552188df08 (release build)
2020-10-03T19:26:47Z Validating signatures for all blocks.
2020-10-03T19:26:47Z Setting nMinimumChainWork=0000000000000000000000000000000000000000000000000000000000000000
2020-10-03T19:26:47Z Using the 'sse4(1way),sse41(4way),avx2(8way)' SHA256 implementation
2020-10-03T19:26:47Z Using RdSeed as additional entropy source
2020-10-03T19:26:47Z Using RdRand as an additional entropy source
2020-10-03T19:26:47Z Default data directory /home/bitcoin/.bitcoin
2020-10-03T19:26:47Z Using data directory /home/bitcoin/.bitcoin/regtest
2020-10-03T19:26:47Z Config file: /home/bitcoin/.bitcoin/bitcoin.conf (not found, skipping)
2020-10-03T19:26:47Z Command-line arg: chain="regtest"
2020-10-03T19:26:47Z Command-line arg: datadir="/home/bitcoin/.bitcoin"
2020-10-03T19:26:47Z Command-line arg: listen=""
2020-10-03T19:26:47Z Command-line arg: printtoconsole=""
2020-10-03T19:26:47Z Command-line arg: rpcallowip="0.0.0.0/0"
2020-10-03T19:26:47Z Command-line arg: rpcauth=****
2020-10-03T19:26:47Z Command-line arg: rpcbind=****
2020-10-03T19:26:47Z Command-line arg: server=""
2020-10-03T19:26:47Z Using at most 125 automatic connections (1048576 file descriptors available)
2020-10-03T19:26:47Z Using 16 MiB out of 32/2 requested for signature cache, able to store 524288 elements
2020-10-03T19:26:47Z Using 16 MiB out of 32/2 requested for script execution cache, able to store 524288 elements
2020-10-03T19:26:47Z Script verification uses 15 additional threads
2020-10-03T19:26:47Z scheduler thread start
2020-10-03T19:26:47Z WARNING: the RPC server is not safe to expose to untrusted networks such as the public internet
2020-10-03T19:26:47Z HTTP: creating work queue of depth 16
2020-10-03T19:26:47Z No rpcpassword set - using random cookie authentication.
2020-10-03T19:26:47Z Generated RPC authentication cookie /home/bitcoin/.bitcoin/regtest/.cookie
2020-10-03T19:26:47Z Using rpcauth authentication.
2020-10-03T19:26:47Z HTTP: starting 4 worker threads
2020-10-03T19:26:47Z Using wallet directory /home/bitcoin/.bitcoin/regtest/wallets
2020-10-03T19:26:47Z init message: Verifying wallet(s)...
2020-10-03T19:26:47Z Using BerkeleyDB version Berkeley DB 4.8.30: (April  9, 2010)
2020-10-03T19:26:47Z Using wallet /home/bitcoin/.bitcoin/regtest/wallets
2020-10-03T19:26:47Z BerkeleyEnvironment::Open: LogDir=/home/bitcoin/.bitcoin/regtest/wallets/database ErrorFile=/home/bitcoin/.bitcoin/regtest/wallets/db.log
2020-10-03T19:26:47Z init message: Loading banlist...
2020-10-03T19:26:47Z ERROR: DeserializeFileDB: Failed to open file /home/bitcoin/.bitcoin/regtest/banlist.dat
2020-10-03T19:26:47Z Invalid or missing banlist.dat; recreating
2020-10-03T19:26:47Z Using /16 prefix for IP bucketing
2020-10-03T19:26:47Z Cache configuration:
2020-10-03T19:26:47Z * Using 2.0 MiB for block index database
2020-10-03T19:26:47Z * Using 8.0 MiB for chain state database
2020-10-03T19:26:47Z * Using 440.0 MiB for in-memory UTXO set (plus up to 286.1 MiB of unused mempool space)
2020-10-03T19:26:47Z init message: Loading block index...
2020-10-03T19:26:47Z Opening LevelDB in /home/bitcoin/.bitcoin/regtest/blocks/index
2020-10-03T19:26:47Z Opened LevelDB successfully
2020-10-03T19:26:47Z Using obfuscation key for /home/bitcoin/.bitcoin/regtest/blocks/index: 0000000000000000
2020-10-03T19:26:47Z LoadBlockIndexDB: last block file = 0
2020-10-03T19:26:47Z LoadBlockIndexDB: last block file info: CBlockFileInfo(blocks=0, size=0, heights=0...0, time=1970-01-01...1970-01-01)
2020-10-03T19:26:47Z Checking all blk files are present...
2020-10-03T19:26:47Z Initializing databases...
2020-10-03T19:26:47Z Pre-allocating up to position 0x1000000 in blk00000.dat
2020-10-03T19:26:47Z Opening LevelDB in /home/bitcoin/.bitcoin/regtest/chainstate
2020-10-03T19:26:47Z Opened LevelDB successfully
2020-10-03T19:26:47Z Wrote new obfuscate key for /home/bitcoin/.bitcoin/regtest/chainstate: 736e3a38a2e0107d
2020-10-03T19:26:47Z Using obfuscation key for /home/bitcoin/.bitcoin/regtest/chainstate: 736e3a38a2e0107d
2020-10-03T19:26:47Z init message: Rewinding blocks...
2020-10-03T19:26:47Z  block index              42ms
2020-10-03T19:26:47Z init message: Loading wallet...
2020-10-03T19:26:47Z BerkeleyEnvironment::Open: LogDir=/home/bitcoin/.bitcoin/regtest/wallets/database ErrorFile=/home/bitcoin/.bitcoin/regtest/wallets/db.log
2020-10-03T19:26:47Z [default wallet] Wallet File Version = 10500
2020-10-03T19:26:47Z [default wallet] Keys: 0 plaintext, 0 encrypted, 0 w/ metadata, 0 total. Unknown wallet records: 0
2020-10-03T19:26:47Z [default wallet] Performing wallet upgrade to 169900
2020-10-03T19:26:48Z [default wallet] keypool added 2000 keys (1000 internal), size=2000 (1000 internal)
2020-10-03T19:26:48Z [default wallet] LegacyScriptPubKeyMan::NewKeyPool rewrote keypool
2020-10-03T19:26:48Z [default wallet] Wallet completed loading in            1324ms
2020-10-03T19:26:48Z [default wallet] setKeyPool.size() = 2000
2020-10-03T19:26:48Z [default wallet] mapWallet.size() = 0
2020-10-03T19:26:48Z [default wallet] m_address_book.size() = 0
2020-10-03T19:26:48Z UpdateTip: new best=0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206 height=0 version=0x00000001 log2_work=1 tx=1 date='2011-02-02T23:16:42Z' progress=1.000000 cache=0.0MiB(0txo)
2020-10-03T19:26:48Z block tree size = 1
2020-10-03T19:26:48Z nBestHeight = 0
2020-10-03T19:26:48Z Failed to open mempool file from disk. Continuing anyway.
2020-10-03T19:26:48Z torcontrol thread start
2020-10-03T19:26:48Z Bound to [::]:18444
2020-10-03T19:26:48Z Bound to 0.0.0.0:18444
2020-10-03T19:26:48Z init message: Loading P2P addresses...
2020-10-03T19:26:48Z ERROR: DeserializeFileDB: Failed to open file /home/bitcoin/.bitcoin/regtest/peers.dat
2020-10-03T19:26:48Z Invalid or missing peers.dat; recreating
2020-10-03T19:26:48Z init message: Starting network threads...
2020-10-03T19:26:48Z net thread start
2020-10-03T19:26:48Z dnsseed thread start
2020-10-03T19:26:48Z 0 addresses found from DNS seeds
2020-10-03T19:26:48Z addcon thread start
2020-10-03T19:26:48Z init message: Done loading
2020-10-03T19:26:48Z dnsseed thread exit
2020-10-03T19:26:48Z opencon thread start
2020-10-03T19:26:48Z msghand thread start
2020-10-03T19:27:49Z Adding fixed seed nodes as DNS doesn't seem to be available.

If I exec into this running container to verify that ports are bound, this is what I find:

λ docker exec -it a744a31c4dd3 /bin/sh
/ # netstat -tan
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 127.0.0.11:41427        0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:18443           0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:18444           0.0.0.0:*               LISTEN
tcp        0      0 :::18444                :::*                    LISTEN
/ #

But when I open a shell in the backing WSL2 instance, I don't find any TCP ports bound at all: enter image description here

And perhaps not unexpectedly, if I try to connect to the WSL2 instance's ip address, the connection is refused.

It seems that there may be some WSL2 issues at play here: https://github.com/microsoft/WSL/issues/4636 https://github.com/microsoft/WSL/issues/4769 https://github.com/microsoft/WSL/issues/4353

But after reading those, I'm not sure if they apply to this situation or not.

Moreover, it seems that this works for a simple netcat listener. If I start a container and open a port using netcat:

λ docker run -it -p "12345" alpine /bin/sh
/ # nc -vvvv -l -p 12345 0.0.0.0
listening on 0.0.0.0:12345 ...

I can show the open port on the WSL2 host:

KENOBI:/tmp/docker-desktop-root/mnt/host/c/Users/Ben# netstat -tan
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 :::12345                :::*                    LISTEN
tcp        0      0 ::ffff:172.24.199.25:12345 ::ffff:172.24.192.1:52429 ESTABLISHED
KENOBI:/tmp/docker-desktop-root/mnt/host/c/Users/Ben#

Using ncat from the Windows 10 host, I can connect to the netcat port: enter image description here

Judging from a working netcat connection from the Windows 10 host to a running WSL2-backed container, it seems that somehow I'm not running bitcoind correctly.

Has anyone else experienced this, and were you able to solve it or find a reasonable workaround?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.