5

This is likely me not understanding how Docker works, but I've tried everything I can think of. I'm trying to start bitcoind in regtest mode inside a Docker container, then execute JSON-RPC commands against the container from the host machine. I'm running Bitcoin 0.18.0.

My Dockerfile looks like

FROM ubuntu:18.04

RUN apt -y update && apt -y install curl
RUN curl -o bitcoin.tar.gz https://bitcoin.org/bin/bitcoin-core-0.18.1/bitcoin-0.18.1-x86_64-linux-gnu.tar.gz
RUN tar xvf bitcoin.tar.gz

RUN mkdir -p /root/.bitcoin
RUN echo "regtest=1" >> /root/.bitcoin/bitcoin.conf \
    && echo "rpcuser=bitcoin" >> /root/.bitcoin/bitcoin.conf \
    && echo "rpcpassword=test" >> /root/.bitcoin/bitcoin.conf \
    && echo "regtest.rpcallowip=0.0.0.0/0" >> /root/.bitcoin/bitcoin.conf \
    && echo "regtest.rpcbind=127.0.0.1" >> /root/.bitcoin/bitcoin.conf

EXPOSE 18443

CMD ["/bitcoin-0.18.1/bin/bitcoind", "-printtoconsole"]

After building the image, I start the container by running

docker run -it -p 127.0.0.1:18443:18443 <image>

I can spawn a shell in the running container and run bitcoin-cli commands successfully.

When trying to execute a bitcoin-cli command from the host machine I get this:

error: Could not connect to the server 127.0.0.1:18443 (error code 1 - "EOF reached")

Make sure the bitcoind server is running and that you are connecting to the correct RPC port.

If I run docker ps I see this:

CONTAINER ID        IMAGE               COMMAND                   CREATED             STATUS              PORTS                        NAMES
b815f8810b6b        90ef5856c984        "/bitcoin-0.18.1/bin…"   25 seconds ago      Up 23 seconds       127.0.0.1:18443->18443/tcp   gallant_rubin

I can run bitcoind on the host machine and successfully execute bitcoin-cli commands against it, so it doesn't appear to be a misconfiguration with the client.

I'm wondering if I'm running into this from the release notes:

The rpcallowip option can no longer be used to automatically listen on all network interfaces. Instead, the rpcbind parameter must be used to specify the IP addresses to listen on. Listening for RPC commands over a public network connection is insecure and should be disabled, so a warning is now printed if a user selects such a configuration. If you need to expose RPC in order to use a tool like Docker, ensure you only bind RPC to your localhost, e.g. docker run [...] -p 127.0.0.1:8332:8332 (this is an extra :8332 over the normal Docker port specification).

Is it even possible run Bitcoin 0.18.0 in a Docker container and use JSON-RPC from the host machine?

2
  • try this, it directly addresses the rpcbind change in 0.18.0 for Docker: bitcoin.stackexchange.com/a/88419/63266 Commented Jul 6, 2019 at 18:57
  • If I'm understanding that correctly, I should just have to replace the relevant lines inside bitcoin.conf with regtest.rpcallowip=0.0.0.0/0 and regtest.rpcbind=127.0.0.1, but that doesn't seem to make a difference.
    – Sam Jones
    Commented Jul 6, 2019 at 22:48

2 Answers 2

1

This was a very simple fix. Instead of regtest.rpcbind=127.0.0.1, I used regtest.rpcbind=0.0.0.0. The logs complain with a warning:

WARNING: the RPC server is not safe to expose to untrusted networks such as the public internet

but since I'm using regtest mode for development, it's not a problem.

0

You if you're on docker, don't publish the RPC port to the host, therefore you're protected, even with rpcbind=0.0.0.0

on docker-compose file, specify the ports in the expose section instead of the ports section

https://docs.docker.com/compose/compose-file/#expose

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.