<p><code>EXPOSE_TCP</code> is implemented in c-lightning's docker script:</p>

<p><a href="https://github.com/ElementsProject/lightning/blob/2945b25b57db37dca31c10da34a4b1ca33d697c3/Dockerfile#L103" rel="nofollow noreferrer">https://github.com/ElementsProject/lightning/blob/2945b25b57db37dca31c10da34a4b1ca33d697c3/Dockerfile#L103</a></p>

<p><a href="https://github.com/ElementsProject/lightning/blob/master/tools/docker-entrypoint.sh" rel="nofollow noreferrer">https://github.com/ElementsProject/lightning/blob/master/tools/docker-entrypoint.sh</a></p>

<p>If you didn't use that script or didn't implement it in your own docker script, it won't work.</p>

<p>It's easy to mistake <code>EXPOSE_TCP</code> for a parameter you can set when spinning up c-lighting.</p>

CC BY-SA 4.0
2019-07-08T01:23:06.090Z
2019-07-08T01:23:06.090Z
gijswijs
<p>You are likely missing a port-binding to your docker image. Since you are able to connect to the port from inside the docker container <code>socat</code> seems to be working.</p>

<p>In order to expose the TCP port to the host OS you need to add <code>-p 9835:9835</code> to your <code>docker</code> command line. That will map the host port 9835 to redirect everything to the guest port 9835, hence making it reachable from the host through the IP 127.0.0.1 which is localhost from the host's point of view.</p>

CC BY-SA 4.0
2019-07-06T12:43:14.277Z
No, that can't be it. The ports are already mapped. If I run `docker ps` I get this output: `0.0.0.0:14302->9835/tcp`. If I then try to run `socat -  tcp:127.0.0.1:14302` on the host nothing happens and the connection closes on itself directly.
gijswijs
CC BY-SA 4.0
2019-07-05T17:31:31.567Z
2019-07-05T17:31:31.567Z
cdecker
<p>If you run a c-lightning node with <code>EXPOSE_TCP</code> set to True, it seems to me it should be possible to connect with it remotely, provided that the c-lightning RCP is listening to all incoming traffic. (IP is set to 0.0.0.0)</p>

<p>I tried the Docker setup recommended in the <a href="https://github.com/ElementsProject/lightning" rel="nofollow noreferrer">c-lightning readme</a> and when I use socat to connect directly from inside the Docker container everything works smooth:</p>

<p><code>socat - UNIX-CONNECT:/home/simnet/.lightning/lightning-rpc</code></p>

<p>But when I try to use socat from the container host the connection closes directly upon opening with no error or anything:</p>

<p><code>socat -  tcp:127.0.0.1:14302</code></p>

<p>The ports seem to be mapped correctly</p>

<p><code>0.0.0.0:14302-&gt;9835/tcp</code></p>

<p>I don't understand what I am missing here. Is it even possible to connect remotely with this setup? I've read <a href="https://bitcoin.stackexchange.com/questions/87417/is-it-possible-to-connect-to-btcpay-server-remote-c-lightning-node">this question</a> as well, and the answer suggests to use socat inside the Docker container to bridge the Unix socket to TCP, but it seems to me that the <code>EXPOSE_TCP</code> is meant to do exactly that natively.</p>

<p><em>UPDATE</em>: The API doesn't really seem to be exposed over TCP after all, although the parameter is certainly set to True.
This is how I found out:</p>

<ul>
<li>I wasn't even able to use the API over TCP from inside the docker container</li>
<li>Then I bridged the Unix socket to TCP manually by using socat. <code>socat -d -d TCP-LISTEN:9835,fork,reuseaddr UNIX-CONNECT:/home/user/.lightning/lightning-rpc</code></li>
<li>After this I was able to connect to the lignting-c node remotely.</li>
</ul>

<p>So maybe there's something wrong with c-lightning in interpreting this setting, or maybe there's something wrong with my setup. I'll explore further and report back.</p>

CC BY-SA 4.0
2019-07-07T12:17:26.163Z
Technically speaking the `EXPOSE_TCP` setting is part of the btcpayserver setup, not c-lightning itself. Looking at the entrypoint script (https://github.com/ElementsProject/lightning/blob/f9f4ed8e1159112a391e45f9971a3d2da7842022/tools/docker-entrypoint.sh) it appears that the comparison with `EXPOSE_TCP` is case-sensitive, so maybe you have used something other that `true` (all lower-case)?
cdecker
CC BY-SA 4.0
2019-07-08T01:24:30.780Z
@cdecker I found the culprit. Thank you for the input.
gijswijs
<core-lightning>
Is it possible to connect remotely to a c-lightning node with an exposed TCP port?
gijswijs
# Is it possible to connect remotely to a c-lightning node with an exposed TCP port?

(Asked by: username_0 on 2019-07-05)

If you run a c-lightning node with `EXPOSE_TCP` set to True, it seems to me it should be possible to connect with it remotely, provided that the c-lightning RCP is listening to all incoming traffic. (IP is set to 0.0.0.0)

I tried the Docker setup recommended in the [c-lightning readme](https://github.com/ElementsProject/lightning) and when I use socat to connect directly from inside the Docker container everything works smooth:

`socat - UNIX-CONNECT:/home/simnet/.lightning/lightning-rpc`

But when I try to use socat from the container host the connection closes directly upon opening with no error or anything:

`socat - tcp:127.0.0.1:14302`

The ports seem to be mapped correctly

`0.0.0.0:14302->9835/tcp`

I don't understand what I am missing here. Is it even possible to connect remotely with this setup? I've read [this question](https://bitcoin.stackexchange.com/questions/87417/is-it-possible-to-connect-to-btcpay-server-remote-c-lightning-node) as well, and the answer suggests to use socat inside the Docker container to bridge the Unix socket to TCP, but it seems to me that the `EXPOSE_TCP` is meant to do exactly that natively.

*UPDATE*: The API doesn't really seem to be exposed over TCP after all, although the parameter is certainly set to True.
This is how I found out:

* I wasn't even able to use the API over TCP from inside the docker container
* Then I bridged the Unix socket to TCP manually by using socat. `socat -d -d TCP-LISTEN:9835,fork,reuseaddr UNIX-CONNECT:/home/user/.lightning/lightning-rpc`
* After this I was able to connect to the lignting-c node remotely.

So maybe there's something wrong with c-lightning in interpreting this setting, or maybe there's something wrong with my setup. I'll explore further and report back.

**Tags:** core-lightning

> **Comments:**
> **username_1**: Technically speaking the `EXPOSE_TCP` setting is part of the btcpayserver setup, not c-lightning itself. Looking at the entrypoint script (https://github.com/ElementsProject/lightning/blob/f9f4ed8e1159112a391e45f9971a3d2da7842022/tools/docker-entrypoint.sh) it appears that the comparison with `EXPOSE_TCP` is case-sensitive, so maybe you have used something other that `true` (all lower-case)?  
> **username_0**: @username_1 I found the culprit. Thank you for the input.  

---

## 2 answers

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

`EXPOSE_TCP` is implemented in c-lightning's docker script:

<https://github.com/ElementsProject/lightning/blob/2945b25b57db37dca31c10da34a4b1ca33d697c3/Dockerfile#L103>

<https://github.com/ElementsProject/lightning/blob/master/tools/docker-entrypoint.sh>

If you didn't use that script or didn't implement it in your own docker script, it won't work.

It's easy to mistake `EXPOSE_TCP` for a parameter you can set when spinning up c-lighting.


---

### Answer by username_1 on 2019-07-05. Score: 1

You are likely missing a port-binding to your docker image. Since you are able to connect to the port from inside the docker container `socat` seems to be working.

In order to expose the TCP port to the host OS you need to add `-p 9835:9835` to your `docker` command line. That will map the host port 9835 to redirect everything to the guest port 9835, hence making it reachable from the host through the IP 127.0.0.1 which is localhost from the host's point of view.

> **Comments:**
> **username_0**: No, that can't be it. The ports are already mapped. If I run `docker ps` I get this output: `0.0.0.0:14302->9835/tcp`. If I then try to run `socat -  tcp:127.0.0.1:14302` on the host nothing happens and the connection closes on itself directly.  

---

