dockerwindows-subsystem-for-linuxtendermint

Unable to expose docker container port other than port 80 to host


Im am running a Tendermint HTTP RPC server at port 26657 on docker container using ubuntu image.

docker run -itd --name t1 -p 26657:26657 tendermint

When I perform a curl operaion inside the container, i get the JSON reponse from the RPC server.

docker exec -it t1 curl localhost:26657/status

But when it try to use the curl operation on the host, then i get an error: "curl: (52) Empty reply from server"

curl localhost:26657/status

Initially I was running docker on a Windows machine. I thought there might be some issue with windows not able to talk with WSL Linux (which docker uses in Windows for ubuntu). So, I tried the same commands in a Linux Virtual Box running Ubuntu 20.04. Still the host ubuntu is not able to access the container server using curl/web browser.

I tried running a apache2 server at port 80 inside container and mapped to port 5000 (-p 5000:80). This worked and I was able to access the apache2 at localhost:5000 in the host. When I try to map 26657 to 5000 (-p 5000:26657) on the RPC server then the same issue happens. So the issue is only with ports other than port 80 in the container.

I tried "netstat -an" on the host machine and it says:"TCP 0.0.0.0:26657 0.0.0.0:0 LISTENING".

Tried running a simple Angular 11 HTTP lite server running at 4200 and mapped to host 4200. It was not able to map this port as well.

Also tried to telnet into port 26657 on host and was able to connect successfully using "telnet localhost 26657". When the container is terminated, then the telnet fails to connect which is ideal. But still not able to connect host using curl/web brower and get the JSON response from the container.

I just tried to run the tendermint RPC server on an Amazon EC2 instance. I was not able to access the port 26657 using the public IP. I guess there is something to do with the protocol on the 26657 port.


Solution

  • I was running the Tendermint RPC server on "localhost" which cannot be accessed from outside. I should have started the server on 0.0.0.0