<p>This was a very simple fix. Instead of <code>regtest.rpcbind=127.0.0.1</code>, I used <code>regtest.rpcbind=0.0.0.0</code>. The logs complain with a warning:</p>
<pre><code>WARNING: the RPC server is not safe to expose to untrusted networks such as the public internet
</code></pre>
<p>but since I'm using regtest mode for development, it's not a problem.</p>

CC BY-SA 4.0
2019-08-13T02:22:13.910Z
2021-02-11T13:38:39.170Z
2021-02-11T13:38:39.170Z
Sam Jones
<p>You if you're on docker, don't publish the RPC port to the host, therefore you're protected, even with <code>rpcbind=0.0.0.0</code></p>

<p>on <code>docker-compose</code> file, specify the ports in the <code>expose</code> section instead of the <code>ports</code> section</p>

<p><a href="https://docs.docker.com/compose/compose-file/#expose" rel="nofollow noreferrer">https://docs.docker.com/compose/compose-file/#expose</a></p>

CC BY-SA 4.0
2019-08-27T12:15:19.737Z
2019-08-27T12:15:19.737Z
DarkW
<p>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.</p>

<p>My Dockerfile looks like</p>

<pre><code>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"]
</code></pre>

<p>After building the image, I start the container by running</p>

<pre><code>docker run -it -p 127.0.0.1:18443:18443 &lt;image&gt;
</code></pre>

<p>I can spawn a shell in the running container and run <code>bitcoin-cli</code> commands successfully.</p>

<p>When trying to execute a <code>bitcoin-cli</code> command from the host machine I get this:</p>

<pre><code>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.
</code></pre>

<p>If I run <code>docker ps</code> I see this:</p>

<pre><code>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
</code></pre>

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

<p>I'm wondering if I'm running into this from the <a href="https://bitcoin.org/en/release/v0.18.0#configuration-option-changes" rel="nofollow noreferrer">release notes</a>:</p>

<blockquote>
  <p>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).</p>
</blockquote>

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

CC BY-SA 4.0
2019-07-06T18:57:56.290Z
try this, it directly addresses the `rpcbind` change in 0.18.0 for Docker:  https://bitcoin.stackexchange.com/a/88419/63266
Chan-Ho Suh
CC BY-SA 4.0
2019-07-06T22:48:44.847Z
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
<bitcoin-core><bitcoind><json-rpc>
Bitcoin Core 0.18.0 in Docker container: Could not connect to the server
Sam Jones
# Bitcoin Core 0.18.0 in Docker container: Could not connect to the server

(Asked by: username_0 on 2019-06-23)

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 

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?

**Tags:** bitcoin-core, bitcoind, json-rpc

> **Comments:**
> **username_1**: try this, it directly addresses the `rpcbind` change in 0.18.0 for Docker:  https://bitcoin.stackexchange.com/a/88419/63266  
> **username_0**: 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.  

---

## 2 answers

### Answer by username_0 on 2019-08-13. Score: 1 | Accepted answer

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.


---

### Answer by username_2 on 2019-08-27. Score: 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>


---

