Bitcoin Core 0.18.0 in Docker container: Could not connect to the server 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 &amp;&amp; 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" &gt;&gt; /root/.bitcoin/bitcoin.conf \
    &amp;&amp; echo "rpcuser=bitcoin" &gt;&gt; /root/.bitcoin/bitcoin.conf \
    &amp;&amp; echo "rpcpassword=test" &gt;&gt; /root/.bitcoin/bitcoin.conf \
    &amp;&amp; echo "regtest.rpcallowip=0.0.0.0/0" &gt;&gt; /root/.bitcoin/bitcoin.conf \
    &amp;&amp; echo "regtest.rpcbind=127.0.0.1" &gt;&gt; /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 &lt;image&gt;


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-&gt;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?
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.